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 Build a Weather App with Swift (Retired) Concurrency Using Our JSON Data

I updated the code from the video to the suggested code for the 6.1 update and I am getting a lot of errors.

This is my code from the last few videos and it worked before I added the sharedSession parts. I checked it several times and I'm not sure what is missing.

        let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")
        let forcastURL = NSURL(string: "39.920032,-86.073166", relativeToURL: baseURL)

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

            var urlContents = NSString(contentsOfURL: NSURL.self, encoding: UInt.self, error: NSErrorPointer.self)
        })
        downloadTask.resume()

    }

Try these changes in your completionHandler:

{(location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in
Colton Ballinger
Colton Ballinger
1,767 Points

Try making the following changes...

Change var urlContents to:

var urlContents = NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil)

Change let downloadTask to:

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