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 Interacting with Data From the Web Writing Concurrent Networking Code

Schott Taylor
PLUS
Schott Taylor
Courses Plus Student 7,125 Points

Force Unwrap? Or Normal Optionals? - Swift: Writing Concurrent Networking Code

So I've encountered a problem following the Swift course "Build a Weather App" and in one point in the video I'm trying to get data from the web, and he force unwraps all his optionals like this:

let dataTask = session.dataTaskWithRequest(request) { (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in print(data!) print("I'm on the backround thread") }

But this gives me and error while his code is error free. I changed my optionals to be normal with a "?" instead of a "!" and the error disappeared but i still didn't retrieve my data. Is there something obvious I'm missing or is there something i don't know?

Can you tell us what the error is that you are getting?

Schott Taylor
Schott Taylor
Courses Plus Student 7,125 Points

The error is: "Cannot convert value of type '(NSData!,NSURLResponse!,NSError!) -> Void'to expected argument type '(NSData?, NSURLReponse?,NSError?) -> Void'