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

Swift Weather app- println(weatherDictionary)

When I do the println(weatherDictionary) nothing happens where the output should be. I even pasted his code in and nothing happened.

Where are you calling the println function?

let sharedSession = NSURLSession.sharedSession() let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in

        if (error == nil){
            let dataObject = NSData(contentsOfURL: location)
            let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject, options: nil, error: nil) as NSDictionary

            let currentWeatherDictionary: NSDictionary = weatherDictionary["currently"] as NSDictionary
            println(currentWeatherDictionary["temperature"])
        }

3 Answers

I believe you may be getting an error. Try writing "println(response, error)" inside the closure (after -> void in ) before the condition if (error == nil). Then you should get some output in the console.

If you get "nil, (something)", then you are encountering an error and therefore not even entering the if statement. If you do get an error like "-1009" I think, you have run into a bug of Xcode 6, you only need to close the project and run it again. If you get a response, then something is wrong with your code, but first try that println() and check for any errors.

okay, thank you!!

Thank you as well! It was error "-1005" for me. Restart did the trick.

Good question,

I would probably start by checking your spelling in the "Current" class and see if temperature value is being stored with that same spelling. Hopefully so.

Also, in comparing it to my code from the project, you're missing the line where you pass in the dictionary to the "Current" class and it returns a Current object (see below). Also, when you make this change, try:

println(currentWeather.temperature)

Getting Current() object:

let dataObject = NSData(contentsOfURL: location)
let weatherDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
let currentWeather = Current(weatherDictionary: weatherDictionary)

Hopefully this helps! Kyle

okay, thank you!!

If that doesn't work, make sure that you have downloadTask.resume() at the end :)