I am trying to make an HTTP Request in an iOS app with Swift using NSURLSession, but XCode throws an error. I've been searching all over stackoverflow and the web and my code is pretty similar to what people suggested, but for some reason it doesn't work. I am on XCode 6.0.1 (6A317).
var session = NSURLSession.sharedSession().dataTaskWithURL(NSURL(url),
completionHandler : {(data, response, error) -> Void in
println("Done")
})
session.resume()
The error points to the first line above: "Extra argument 'completionHandler' in call"
Using Trailing Closure throws a similar error:
var session = NSURLSession.sharedSession().dataTaskWithURL(NSURL(url)) {(data, response, error) -> Void in
println("Done")
}
session.resume()
The error is also on the first line: "Extra argument in call"
Did I miss something here?
Simple get request would be like this:
let task = NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "url_here")) { data, response, error in
}
task.resume()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With