error handling with swift 2.0 is different and ran into the wall when was trying to setup the NSURL Session and using the completion handler where the error parameter is available in swift 1.2 but when looking at documentation the error parameters is no longer there and it is trying to tell me to use throwing function statements instead, not really familiar with syntax. The block quotes are where the error messages appear and this code works just fine with Xcode 6.4 or earlier but not with 7.0
/Volumes/MyData/AppDevXcode7/Training/iOS8.0Dev/connecting_swift/connecting_swift/JSONViewController.swift:28:78: Invalid conversion from throwing function of type '(_, _, _) throws -> _' to non-throwing function type '(NSData?, NSURLResponse?, NSError?) -> Void'
@IBAction func callURLButtonTapped(sender: AnyObject){
urlTextField.resignFirstResponder()
let requestedURL = NSURL(string: urlTextField.text!)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(requestedURL!, completionHandler: {data, response, error in
if let actualError = error {
let errorResponse = "Response status: \(actualError.description)"
self.responseText.text = errorResponse
}else{
var parseError: NSError?
let jsonArray = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &parseError ) as! NSDictionary
if let actualParseError = parseError {
let errorResponse = "Response status: \(actualParseError.description)"
self.responseText.text = errorResponse
}else{
dispatch_async(dispatch_get_main_queue(), {
let httpResponse = response as! NSHTTPURLResponse
let responseStatus = "Response status: \(httpResponse.statusCode)"
self.responseStatusLabel.text = responseStatus
let responseAsString = jsonArray.description
self.responseText.text = responseAsString
})
}
}
})
task.resume()
}