我是xcode编程的新手,我正在尝试在Swift 2中实现一个发出HTTP Get请求的App.升级xcode 7后显示错误:
Cannot convert value of type
'(NSData!, response: NSURLResponse!, err: NSError!) -> ()'
to expected argument type
'(NSData?, NSURLResponse?, NSError?) -> Void'
Run Code Online (Sandbox Code Playgroud)
(此代码段使用swift 1.2的旧错误处理.)任何人都可以帮助我,请问如何在Swift 2.0中实现它.
request.HTTPMethod = "GET"
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithRequest(request, completionHandler:loadedData)
task.resume()
}
func loadedData(data:NSData!, response:NSURLResponse!, err:NSError!){
if(err != nil)
{
print(err?.description)
}
else
{
var jsonResult: NSDictionary = NSDictionary()
let httpResponse = response as! NSHTTPURLResponse
print("\(httpResponse.statusCode)")
if (httpResponse.statusCode == 200)
{
jsonResult = (try! NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers)) as! NSDictionary
print(jsonResult) …Run Code Online (Sandbox Code Playgroud)