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 trialdavidmartin
4,288 PointsOn the playground i get an optional value of forecastURL
On my playground the value of
println(forecastURL) is
"Optional(42.012898,-4.515968 -- https://api.forecast.io/forecast/0818ad4e96f643b80ceb76b5b7b82289/)"
so let weatherData = NSData(contentsOfURL: forecastURL!, options: nil, error: nil) is nil
4 Answers
Daniel Sattler
4,867 PointsOh sorry hehe... i didnยดt see this in your previous post. to unwrap an optional item you do so by adding a " ! " at the end.
println(forecastURL)
becomes
println(forecastURL!)
I hope this helps ;-)
Daniel Sattler
4,867 Pointshow did you define forecastURL ?
davidmartin
4,288 Pointslet apiKey="0818ad4e96f643b80ceb76b5b7b82289" let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/") let forecastURL = NSURL(string: "42.012898,-4.515968", relativeToURL: baseURL)
davidmartin
4,288 PointsThanks a lot , I forget the "!" symbol