Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Weather App with Swift (Retired) Concurrency Using Our JSON Data

Getting error "Use of unresolved identifier 'urlContents'.

Copy of code: class ViewController: UIViewController {

private let apiKey = "00bd1d14e13bd044bdb542e26303873d"

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let baseUrl = NSURL(string:"https://api.forecast.io/forecast/\(apiKey)/")
    let forecastUrl = NSURL(string: "26.361857,-80.071547", relativeToURL: baseUrl)

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

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



    })
    downloadTask.resume()

2 Answers

Hi Chapin!

I noticed right here, that you didn't store this block of code in a constant:

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

So instead, it should look something like this:

let urlContents = NSString(contentsOfURL: location, encoding: NSUTF8StringEncoding, error: nil)
println(urlContents)
Greg Kaleka
Greg Kaleka
39,019 Points

Hey Ronaldo - just an FYI that I cleaned up your formatting a bit.

Greg Kaleka
Greg Kaleka
39,019 Points

Hi Chapin,

You're trying to println urlContents, which you haven't defined as a constant or variable. What are you trying to print, exactly?