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

Cleaning up our date - iOS Swift Building a Weather App

My code gets an error and I'm not sure why. Once I get to the "println(currentWeather.temperature)" line the error says, "use of unresolved identifier 'currentWeather'".

'''html <p> class ViewController: UIViewController {

let apiKey = "962207ed0273d1f2d1ad4a06b856c387"

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    //let forcastURL = "https://api.forecast.io/forecast/
    //962207ed0273d1f2d1ad4a06b856c387/39.920032,  -86.073166"

    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

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


        let currentweather = Current(weatherDictionary: weatherDictionary)
            println(currentWeather.temperature)



        }
    })
    downloadTask.resume()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

} </p> '''

Swift is case sensitive. You've declared currentweather without camel case so when you've used it again as currentWeather in the next line it's not recognised. Try changing your let statement to:

let currentWeather = Current(weatherDictionary: weatherDictionary)

and see if that works

1 Answer

Thanks.