Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,662 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,662 Points

No problem, glad you got it working.