Swift3 将URLSession更新为swift 3引发错误

Swift3 将URLSession更新为swift 3引发错误,swift3,Swift3,我将代码更新为Swift 3,除URLSession外,大部分代码都转换为fine,我无法找到此错误的解决方案: 无法使用类型为“”的参数列表调用“dataTask”(使用:NSMutableURLRequest,completionHandler:(数据?、URLResponse?、NSError?->Void)的参数列表) 这是我的代码: let post:NSString = "username=\(username)&userPassword=\(password)&am

我将代码更新为Swift 3,除URLSession外,大部分代码都转换为fine,我无法找到此错误的解决方案:

无法使用类型为“”的参数列表调用“dataTask”(使用:NSMutableURLRequest,completionHandler:(数据?、URLResponse?、NSError?->Void)的参数列表)

这是我的代码:

    let post:NSString = "username=\(username)&userPassword=\(password)&userEmail=\(email)" as NSString

    let url:URL = URL(string: "http://ec2-54-201-55-114.us-west-2.compute.amazonaws.com/wickizerApp/ApplicationDB/scripts/registerUser.php")!

    let request = NSMutableURLRequest(url: url)
    request.httpMethod = "POST"
    request.httpBody = post.data(using: String.Encoding.utf8.rawValue)


    URLSession.shared.dataTask(with: request, completionHandler: { (data:Data?, response:URLResponse?, error:NSError?) -> Void in

        DispatchQueue.main.async
            {

                if error != nil {
                    self.displayAlertMessage(error!.localizedDescription)
                    return
                }

                do {
                    let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary

                    if let parseJSON = json {

                        let status = parseJSON["status"] as? String

                        if( status! == "200")
                        {
                            let myAlert = UIAlertController(title: "Alert", message: "Registration successful", preferredStyle: UIAlertControllerStyle.alert);

                            let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default){(action) in

                                self.dismiss(animated: true, completion: nil)
                            }

                            myAlert.addAction(okAction);
                            self.present(myAlert, animated: true, completion: nil)
                        } else {
                            let errorMessage = parseJSON["message"] as? String
                            if(errorMessage != nil)
                            {
                                self.displayAlertMessage(errorMessage!)
                            }

                        }

                    }
                } catch{
                    print(error)
                }



        }

    }).resume()

在swift 3中是否有不同的请求方式,或者只是更改了请求方式?

编译器希望
URLRequest
Error

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = post.data(using: .utf8)

URLSession.shared.dataTask(with: request, completionHandler: { (data:Data?, response:URLResponse?, error:Error?) -> Void in

})
还是更短

URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in

})
URLSession.shared.dataTask(with: request) { (data, response, error) in

}
还是更短

URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in

})
URLSession.shared.dataTask(with: request) { (data, response, error) in

}

编译器需要
URLRequest
Error

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = post.data(using: .utf8)

URLSession.shared.dataTask(with: request, completionHandler: { (data:Data?, response:URLResponse?, error:Error?) -> Void in

})
还是更短

URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in

})
URLSession.shared.dataTask(with: request) { (data, response, error) in

}
还是更短

URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in

})
URLSession.shared.dataTask(with: request) { (data, response, error) in

}
可能的重复可能的重复