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

yi yuan
yi yuan
2,436 Points

Sample Code doesn't work

I have followed the tutorial and also update the code syntax based on the Teacher's Notes, but let baseURL = NSURL(fileURLWithPath: "https://api.forecast.io/forecast/\(apiKey)/") let forecastURL = NSURL(string: location, relativeToURL: baseURL) let weatherData = NSData(contentsOfURL: forecastURL, options: nil, error: nil) still doesn't work. Even the code I download from the sample is still not working. Any idea or update, please help! Thanks.

5 Answers

Oliver Pinchbeck
Oliver Pinchbeck
2,732 Points

Maybe check your Xcode version? The NSData function changed between Xcode 6.0 and 6.1 I think

Ludwing Najera
Ludwing Najera
4,596 Points

The same thing's happening to me, and the console says "fatal error: unexpectedly found nil while unwrapping an Optional value". Does that mean anything to any of you?

Oliver Pinchbeck
Oliver Pinchbeck
2,732 Points

Just checking, but you put in your real API Key, right?

Ludwing Najera
Ludwing Najera
4,596 Points

Yes, I did put in my real API Key.

yi yuan
yi yuan
2,436 Points

Still don't know why. And this form has been well developed enough for me to easily find the answer or wait for answer. Waiting..

Queenie Peng
Queenie Peng
8,052 Points
  1. Check if there's any space in baseURL and forecastURL
  2. Use "!" to unwrap the optional value