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

Connecting the UI to our model - Building a Weather App -> source code crashes repeatedly

The source code crashes every few seconds even though it is fully updated to version 6.1.1.

''' import Foundation import UIKit

class ViewController: UIViewController {

@IBOutlet weak var iconView: UIImageView!
@IBOutlet weak var currentTimeLabel: UILabel!
@IBOutlet weak var temperatureLabel: UILabel!
@IBOutlet weak var humidityLabel: UILabel!
@IBOutlet weak var precipitationLabel: UILabel!
@IBOutlet weak var summaryLabel: UILabel!


let apiKey = "962207ed0273d1f2d1ad4a06b856c387"

override func viewDidLoad() {
    super.viewDidLoad()

    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)

        /*dispatch_async(dispatch_get_main_queue(), { () ->
                void in
                self.temperatureLabel.text = "\(currentWeather.temperature)"

            })*/



        }
    })
    downloadTask.resume()

}

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

} '''

The lines that are commented out seem to be causing the problem since taking them out stop the "SourceKitService Crashed" message.

1 Answer

Pavel Fomchenkov
Pavel Fomchenkov
20,897 Points

Check your temperatureLabel outlet connection in your storyboard.

Thanks. I ended up retyping it and it works now.