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 trialJames Lambert
Courses Plus Student 14,477 PointsMy api key is correct and all my code is identical. Why am I getting nil?
My code for the stormy app is just returning nil. I have check and rechecked my apiKey. I don't have spaces in the url. I am not crashing. I am just printing out nil.
let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/")
let forecastURL = NSURL(string:"43.650165,-116.279280", relativeToURL: baseURL)
let weatherData = NSData(contentsOfURL: forecastURL!, options: nil, error: nil)
println(weatherData)
wachter
1,594 PointsI have the exact same code as you and I am also getting nil. However my network is fully working so that shouldn't be the problem. What could it be?
1 Answer
James Lambert
Courses Plus Student 14,477 PointsI didn't change anything, and it has been working fine now. Can't explain it. I think it had to do with something on their end. I have been testing it for weeks (since I posted this) and it hasn't quit yet. My app is in review right now. I used this tutorial to add a weather feature to an event app I wrote. If your running in the simulator, turn your wifi off and back on and try to run the app. See if it still gets nil.
James Lambert
Courses Plus Student 14,477 PointsJames Lambert
Courses Plus Student 14,477 PointsEveryone. It was a network problem. It started working without any changes.