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 trialJason Holt
10,041 PointsValue of option type NSURL? not unwrapped.
''let downloadTask: NSURLSessionDownloadTask = ''sharedSession.downloadTaskWithURL(forecastURL, completionHandler: { (location: NSURL!, ''response: NSURLResponse!, error: NSError!) -> Void in
This line of code returns the following error: Value of optional type NSURL? not unwrapped; did you mean to use ! or ?
Adding bangs removes the errors but is this the right thing to do here?
1 Answer
Chris Shaw
26,676 PointsHi Jason,
As of Xcode 6.1 this is how NSURL
is expected to work, before 6.1 instances of NSURL
didn't behave as optionals which meant it was difficult to test against invalid strings whereas now we can test for that, in this course no testing occurs but in a real app you would want to ensure the URL validates before making the request.
Jason Holt
10,041 PointsJason Holt
10,041 PointsThanks for the info. Just what I was looking for.