昨日私はXcode 8.2にアップデートしたので、Swift 3.0の構文に更新する必要がありました。私のアプリでは、私はこの機能を持っている:Swift3の問題:新しい構文を理解できない
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()
}
をそして、私はこのエラーを取得する:
Cannot invoke 'dataTask' with an argument list of type '(with: NSMutableURLRequest, completionHandler: (Data?, URLResponse?, NSError?) -> Void)'
、誰かが私はそれを修正するために役立つだろうしてください?あなたがApple Documentation
をチェックすると
Xcode 8.2ではSwift 3.0に更新する必要はありませんが、Swift 2.3を使用することはできます。しかし、Xcode 8.3では、Swift 3.xに移行する必要があります。 –