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

Getting an error here with the new code: "fatal error: unexpectedly found nil while unwrapping an Optional value"

This is my code that's causing the error:

        let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")
        // Do any additional setup after loading the view, typically from a nib.

        let forecastURL = NSURL(string: "40.712908, -73.949399", relativeToURL: baseURL)

        let weatherData = NSData(contentsOfURL: forecastURL!, options: nil, error: nil)

2 Answers

Ah, nm, found the error, I had a space between my coordinates when I copied and pasted from Google Maps. Removed the space, and now it works fine.

Ami Bhimani
Ami Bhimani
6,373 Points

let forcastURL = NSURL(string: "00.000000, __ -00.000000", relativeToURL: baseURL)

REMOVE SPACE __ and replace to

let forcastURL = NSURL(string: "00.000000,-00.000000", relativeToURL: baseURL)