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

Suyu Ren
Suyu Ren
526 Points

I keep on getting error with my code: let downloadTask: NSURLSessionDownloadTask = shareSession.downloadTaskWith

let downloadTask: NSURLSessionDownloadTask = shareSession.downloadTaskWithURL(forecastURL, completionHandler: {(location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in

It says value of optional type "NSURL" not unwrapped

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Suyu,

The error is simply asking you to unwrap the variable forecastURL using the exclamation mark or bang as it's known which you've already done in other parts of the code, e.g.

shareSession.downloadTaskWithURL(forecastURL!)

Of course that's not all of the required code but it shows you what you need to do, optionally you can also unwrap the NSURL object on the same line as where the variable is instantiated but it's more of a personal preference.

Suyu Ren
Suyu Ren
526 Points

Thank you, Chris. It seems working now.

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Suyu Ren.

I have just tried to download Pasan's code and as soon as I open the whole project up (from the downloaded file, without touching it) I have the same error in the ViewController.swift file..

So I have tried to reopen my Swift project and the same error is there too...

Not sure what may be the problem there, I have to presume something changed in xcode?

Someone knows more?

ty

Suyu Ren
Suyu Ren
526 Points

Thank you, Vittorio.

I just updated my Xcode to 6.1. Will it be the issue?