Yesterday I updated to Xcode 8.2 which forced me to update to Swift 3.0 syntax. In my app I have this function:
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()
}
And I get this error:
Cannot invoke 'dataTask' with an argument list of type '(with: NSMutableURLRequest, completionHandler: (Data?, URLResponse?, NSError?) -> Void)'
Please, would someone help me to correct it?