I'm trying to handle a completed URL request in Swift 2.2 and check for errors but the line starting with completionHandler:{(response: NSURLResponse...
in the code below is throwing the error:
cannot convert value of type '(NSURLREsponse!, NSData!, NSError!) - Void' to expected argument type '(NSURLResponse?, NSData?, NSError?) -> Void'.
I have a suspicion I need to use a do-try-catch but I'm not certain if there's a simpler way or not.
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(),
completionHandler: {
(response: NSURLResponse!, data: NSData!, error: NSError!) - > Void in
if error == nil {
var image = UIImage(data: data)
dispatch_async(dispatch_get_main_queue(), {
cell.selfieImgView.image = image
})
} else {
print("Error: \(error.localizedDescription)")
}
})
return cell
}