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) Displaying Our Weather Data Connecting the UI to Our Model

Somthing is wrong with the interaction with the ui to the code

So i think the ui and the code is breaking each other

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:"28.014087,-82.787620", relativeToURL: baseUrl)

    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 currentWeather = Current(weatherDictionary:weatherDictionary)

            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                self.temperatureLabel.text = "\(currentWeather.temperature)"
                self.temperatureLabel.text = "\(currentWeather.temperature)"
                self.iconView.image = currentWeather.icon!
                self.currentTimeLabel.text = "At \(currentWeather.currentTime!) it is"
                self.humidityLabel.text = "\(currentWeather.humidity)"
                self.precipitationLabel.text = "\(currentWeather.precipProbability)"
                self.summaryLabel.text = "\(currentWeather.summary)"
            })

        }

    })
    downloadTask.resume()

I believe my code is good but it keeps showing me an error in the appledelagate file. I went back and deleted the UI items and kept the screen blue and when i ran the code everything went fine. so i think its the dispatch call not seperating the call from the ui