Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Jef Djandji
Jef Djandji
1,229 Points

Get daily forecast from JSON in Swift


I finished the Weather app tutorial ! And I love it !

However, I would like to go further, and add the forecast for the next few days. How can I extract the data from the JSON dictionary from the daily parameter?

I created a new .swift file, very similar to the Current.swift file we created during the tutorial.

Inside this new file, I want to extract the data for tomorrow.

Instead of having:

init(weatherDictionnary: NSDictionary){
     let currentWeather = weatherDictionnary["currently"] as NSDictionary 

I guess I should have something like:

init(weatherDictionnary: NSDictionary){ 
let dailyWeather = weatherDictionnary["daily"] as NSDictionary
let tomorrowWeather = dailyWeather["data"] as NSDictionary 

But this is not working... Any solutions?

Thank you.

3 Answers

Pasan Premaratne
Pasan Premaratne
Treehouse Teacher

Hey Jef Djandji

Glad you liked the course and congratulations on completing it!!

Spoiler Alert: We will be enhancing the app in the next course to work with daily data but I don't want you to sit around waiting on me :)

The reason you're not getting the values you want is because of the way the JSON data is structured. The data retrieved when you pass in the "data" key to dailyWeather is not a dictionary. Hint: Try one of the other data structures we covered in the course.

Jef Djandji
Jef Djandji
1,229 Points

Thank you Pasan Premaratne !

I wanted to let you know, I found out how to do it, as well as adding the geolocation function.

I will soon publish the app on the App Store.

Thank you again for the help and the great tutorials.

mind pasting your link to app store. i would like to download it. we support each other in here. :)

Jef Djandji
Jef Djandji
1,229 Points

Here is the link: https://appsto.re/fr/9Hq62.i

I am working on a new update, it will hopefully be available withing the next 2 weeks.