昨天我更新到 Xcode 8.2,这迫使我更新到 Swift 3.0 语法。在我的应用程序中,我有这个功能:
func performGetRequest(_ targetURL: URL!, completion:@escaping (_ data: Data?, _ HTTPStatusCode: Int, _ error: NSError?) -> Void)
{
let request = NSMutableURLRequest(url: targetURL)
request.httpMethod = "GET"
let sessionConfiguration = URLSessionConfiguration.default
let Session = URLSession(configuration: sessionConfiguration)
let tasksession = Session.dataTask(with: request, completionHandler: { (data: Data?, response: URLResponse?, error: NSError?) -> Void in
if data != nil{
DispatchQueue.main.async(execute: { () -> Void in
completion(data: data, HTTPStatusCode: (response as! HTTPURLResponse).statusCode, error: error)})
}
else
{
print("Connection Lost")
}
})
tasksession.resume()
}
我得到这个错误:
无法使用类型为“(带有:NSMutableURLRequest,completionHandler:(Data?,URLResponse?,NSError?)-> Void)”类型的参数列表调用“dataTask”
拜托,有人能帮我纠正吗?