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) Pulling Data From the Web Making a Network Call

Kennen Pflughoeft
Kennen Pflughoeft
2,749 Points

Why is my app terminating?

I believe I have the same code as in the example, but I am getting an error saying:

2014-10-01 15:58:51.629 Stormy[5736:90736] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSPlaceholderData initWithContentsOfURL:options:error:]: nil URL argument' *** First throw call stack:

Here is the code I've written:

import UIKit

class ViewController: UIViewController {

    private let apiKey = "3c531cb8bc268e115000fc33ef72a6a2"

    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: "37.768796, -122.447933", relativeToURL: baseURL)

        let weatherData = NSData.dataWithContentsOfURL(forecastURL, options: nil, error: nil)

        println(weatherData)
    }

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


}

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Kennen,

You have an space in your lat and lng coordinates which is the only issue I see, change it to the below and hopefully your app will work as expected.

let forecastURL = NSURL(string: "37.768796,-122.447933", relativeToURL: baseURL)
Kennen Pflughoeft
Kennen Pflughoeft
2,749 Points

Perfect! This fixed the problem. Thanks!

Chris Shaw
Chris Shaw
26,676 Points

No problem, glad you got it working.