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

The video show one way but I get an error saying Error

let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")
        let forecastURL = NSURL(string: "40.415779, -74.242488", relativeToURL: baseURL)

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

            NSString.stringWithContentsOfURL(url: NSURL(), encoding: UInt(), error: NSErrorPointer())

It says one way in the video but I get errors because of Xcode 6.1

2 Answers

I don't get what you're asking, but that line of code that converts your response to a string is incorrectly formed. Fill in those parameters with the results you get from your request and print to screen in String format.

let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")
let forecastURL = NSURL(string: "40.415779, -74.242488", relativeToURL: baseURL)
let sharedSession = NSURLSession.sharedSession()
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: {
            (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in

            var stringedResponse = NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil) //pass in your 'location' object from the response you got. Use UTF-8 string encoding. Set the error parameter to nil.
println(stringedResponse)
}
downloadTask.resume()

Thanks that what I was looking for

Sean Lee
Sean Lee
5,196 Points

I don't get what you're asking either, but try taking out the space out after the comma in your coordinates: "40.415779, -74.242488"