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 trialDavid Bauer
3,863 PointsCannot invoke "dataTaskWithRequest" with an argument list of type "(NSURLRequest, completionHandler: (NSData!,...
Hi, I added my code like Pasan did and I'm getting multiple errors. Here is my code:
// Use NSURLSession API to fetch data
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: configuration)
// NSURLRequest Object
let request = NSURLRequest(URL: forecastURL!)
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in
print(data)
})
I am using Xcode 7 beta with Swift 2.0 Does anyone know what I did wrong here?
Thanks!
David Bauer
3,863 PointsPiplup Pochama I haven't the code anymore but I'm sure I solved this problem. Can you paste more code in here so that I can look at it?
Unsubscribed User
Courses Plus Student 22,129 PointsPiplup Pochama If i can remember correctly in xCode 7 swift 2.1 you can remove the option and error from the argument like so:
let weatherData = NSData(contentsOfURL: forecastURL!)
try that and let me know if you have any success
2 Answers
David Bauer
3,863 PointsOk, seems like I found the answer:
let dataTask = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in
print(data)
})
Ramesh VJ
2,201 PointsThanks David for the answer.
@ Piplup Pochama the error in
let weatherData = NSData(contentsOfURL: forecastURL!, options: nil, error: nil)
got fixed when I Used the below code instead
let weatherData = NSData(contentsOfURL: forecastURL!)
Piplup Pochama
16,851 PointsPiplup Pochama
16,851 PointsThanks for this! Been trying to find the answer for this.
Any chance you know how to fix the NSData version from the earlier lecture?
let weatherData = NSData(contentsOfURL: forecastURL!, options: nil, error: nil)