I have this code
let path : String = "http://apple.com"
let lookupURL : NSURL = NSURL(string:path)!
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(lookupURL, completionHandler: {(data, reponse, error) in
let jsonResults : AnyObject
do {
jsonResults = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
// success ...
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
}
// do something
})
task.resume()
but it is failing on the let task
line with the error:
invalid conversion from throwing function of type (__.__.__) throws to non throwing function type (NSData?, NSURLResponse?, NSError?) -> Void
what is wrong? This is Xcode 7 beta 4, iOS 9 and Swift 2.
edit:
the problem appears to be with these lines
do {
jsonResults = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
// success ...
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
}
I remove these lines and the let task
error vanishes.