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) Data Modeling With Structures Cleaning Up Our Date

lldb - unwrapping error

let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary

Always gives me lldb error without any text.

2 Answers

Stone Preston
Stone Preston
42,016 Points

using dataObject! means to go ahead and unwrap the optional. basically you are saying you know that its not nil.

dataObject is probably nil so its crashing. post the line of code where you set the value of dataObject

It is not working even without the exclamation mark.

class ViewController: UIViewController {

private let apiKey = "apiblahblahkey"

override func viewDidLoad() {
    super.viewDidLoad()

    let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")

    let forecastURL = NSURL(string: "48.854441,17.123582", 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)

            println(currentWeather.humidity)
        }
    })

    downloadTask.resume()



}

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

}

Stone Preston
Stone Preston
42,016 Points

put the ! back and add a print statement after you set the data object so we can see what the value is:

 if (error == nil) {
                let dataObject = NSData(contentsOfURL: location)
                 println("dataObject: \(dataObject)")

run it and see if it prints out nil. if its nil there is an issue with the download task

It is still printing just (lldb).

Stone Preston
Stone Preston
42,016 Points

scroll down. there should be more info in the console. can you copy and paste everything htats in the console

I think I am just an idiot, nothing else. I've probably hit a breakpoint and Xcode just stop on it :-D

Well, I am still confused with Swift and Xcode (done some work in JAVA past).

Thank you very much, problem solved :-) Now it's printing temperature value.