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

Access to API returning NIL

I'm having problems accessing the API. In this xcode returning NIL, but if I use the URL in the browser works normally. Can be setup?

Note: The counter in the forecast site computing access.

My code in playground:

let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")
let forecastURL = NSURL(string: "37.8267,-122.423?units=si&lang=pt", relativeToURL: baseURL)

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

can you post your code

1 Answer

Are you sure your API key is correct?

I copied your code exactly as you had it with an API key I created and it worked just fine. That's the only difference I saw.

Using NSURLSessionDownloadTask work in implementing the app, but still does not work on the playground.

Can be setup? And the playground is no access?