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) Concurrency Using Our JSON Data

Nil returned when using NSData(contentsOfURL : forecastURL!)

private let apiKey = "key"

let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")

let forecastURL = NSURL(string: "40.724245,-73.562374", relativeToURL: baseURL)


let weatherData = NSData(contentsOfURL: forecastURL!)

I'm completely lost. When I call forecastURL! in playground without NSData, I get the correct url Displayed.

However, using the NSData(contentsOfURL: forecastURL! ) to call weatherData returns a nil value.

2 Answers

Waited 1hr and magically it worked.

David Batista da Silva
David Batista da Silva
1,479 Points

I am having the same problem. When I put the URL in the browser works, but in xcode always returns NIL.

I am testing since yesterday.