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

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