Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Weather App with Swift (Retired) Pulling Data From the Web Making a Network Call

On 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
Daniel Sattler
4,867 Points

Oh 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
Daniel Sattler
4,867 Points

how did you define forecastURL ?

let apiKey="0818ad4e96f643b80ceb76b5b7b82289" let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/") let forecastURL = NSURL(string: "42.012898,-4.515968", relativeToURL: baseURL)

Thanks a lot , I forget the "!" symbol