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 Writing Concurrent Networking Code

Seth Dobrin
Seth Dobrin
1,459 Points

downloadTask error in Weather App

I am getting two errors with the code I thought I copied from the leson

let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL, completionHandler: { (location: NSURL!, response: <#NSURLResponse!#>, error: <#NSError!#>) -> Void in println(response) }) downloadTask.resume()

but I get two errors Expected an identifier to name the generic parameter Expected parameter type following

I can figure out what I am doing wrong here

Michael Baker
Michael Baker
5,709 Points

I am having the same problem.

5 Answers

Paul Gustafson
Paul Gustafson
5,041 Points

I also noticed that I must add a

downloadTask.resume()

after your let downloadTask, like so:

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

Not quite sure why, I am a newbie but it seems like the request doesn't get sent unless that is added.

XCODE VERSION: Version 6.2 (6C131e)

Greg Melson
Greg Melson
3,037 Points

I think you may need to change this i.e. replace "response:, error:"
with "response: NSURLResponse!, error: NSError!"

to make it the same as what was shown in the lesson i.e. let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError! ) -> Void in println(response) }) downloadTask.resume()

I don't know if that will fix it but I just noticed that it was missing

I get this error after that "Value of optional type 'NSURL?' not unwrapped; did you mean to use '!' or '?'?"

I'm on Xcode Version 6.1.1 (6A2008a) and Yosemite 10.10.2 But hope the above helps you with your error - I'll keep looking for the answer to mine

Greg Melson
Greg Melson
3,037 Points

ok just to add to that for some reason you need to unwrap the "forcastURL" constant i.e. "forcastURL!" then everything works

let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forcastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError! ) -> Void in println(response) })

..weird I did this a few times but it only now worked. I also closed and reopened Xcode for what it's worth, it's working now - Good luck to you on yours

Greg Melson
Greg Melson
3,037 Points

ok just to add to that for some reason you need to unwrap the "forcastURL" constant i.e. "forcastURL!" then everything works

let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forcastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError! ) -> Void in println(response) })

..weird I did this a few times but it only now worked. I also closed and reopened Xcode for what it's worth, it's working now - Good luck to you on yours

Greg Melson
Greg Melson
3,037 Points

ok just to add to that for some reason you need to unwrap the "forcastURL" constant i.e. "forcastURL!" then everything works

let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forcastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError! ) -> Void in println(response) })

..weird I did this a few times but it only now worked. I also closed and reopened Xcode for what it's worth, it's working now - Good luck to you on yours