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

iOS

Accessing weather information for next 3 days, not just current

in the weather app, we are accessing the current weather data using the keyword "currently" - if I instead wanted to access the weather data for the next three days how can I go about accessing the data from the "daily" dictionary? It looks like there is an embedded dictionary inside?

4 Answers

Hi Steve, could we get a code sample on how to access a value inside the daily dictionary? The JSON data prints below (i simplified it a bit):

{
    currently =     {
        apparentTemperature = "51.21";
    };
    daily =     {
        data =         (
                        {
                apparentTemperatureMax = "51

I'm able to access the currently dictionary as instructed in the video with:

let currentWeather = weatherDictionary["currently"] as NSDictionary

        temperature = currentWeather["temperature"] as Int

But then, how would I access the daily data? I've tried below with no luck. I thought the ( would mark an array, and so I'd be accessing the value in the daily key-value pair, and then accessing an array of the information inside that value. Is that incorrect?

let dailyWeather = weatherDictionary["daily"] as NSDictionary

        temperature = currentWeather["data"][0] as Int

Yes, the weather data is presented in the same (roughly) format for currently, minutely, hourly and daily.

The one's that aren't currently have a Unix timestamp, so you'll need to add that to your dictionary access.

You can access them the same way but you may want to add a tabbed View to make navigation more simple.

Let me know if I can help!

Steve.

Hi Christopher,

There's a whole course dedicated to the subject.

I'll find you a link ... or check out my Github repo, if you want.

Steve.