Swift2 在Swift 2额外参数的更改中';错误';随时待命

Swift2 在Swift 2额外参数的更改中';错误';随时待命,swift2,Swift2,升级至适用于iOS 9的Xcode 7 Swift 2和SDK。我在调用“我的代码是: let myUrl = NSURL(string: "http://localhost/SwiftAppAndMySQL/scripts/registerUser.php"); let request = NSMutableURLRequest(URL:myUrl!); request.HTTPMethod = "POST"; let postString =

升级至适用于iOS 9的Xcode 7 Swift 2和SDK。我在调用“我的代码是:

let myUrl = NSURL(string: "http://localhost/SwiftAppAndMySQL/scripts/registerUser.php");
        let request = NSMutableURLRequest(URL:myUrl!);
        request.HTTPMethod = "POST";

        let postString = "userEmail=\(userEmail)&userFirstName=\(userFirstName)&userLastName=\(userLastName)&userPassword=\(userPassword)";

        request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding);

        NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data:NSData!, response:NSURLResponse!, error:NSError!) -> Void in

            dispatch_async(dispatch_get_main_queue())
            {                    
                spinningActivity.hide(true)

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

                var err: NSError?
                var json = NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers, error: &err) as? NSDictionary

                if let parseJSON = json {

                    var userId = parseJSON["userId"] as? String

                    if( userId != nil)
                    {
                        var myAlert = UIAlertController(title: "Alert", message: "Registration successful", preferredStyle: UIAlertControllerStyle.Alert);

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

                            self.dismissViewControllerAnimated(true, completion: nil)
                        }

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

        }).resume()
NSURLSession.sharedSession().dataTaskWithRequest(请求,completionHandler)要求您提供3个可选参数,您将提供3个强制展开参数

尝试改变

NSURLSession.sharedSession().dataTaskWithRequest(request) { (data:NSData!, response:NSURLResponse!, error:NSError!)


现在正在工作,我用以下代码替换了以前的代码:

让myUrl=NSURL(字符串:“”); let request=NSMutableURLRequest(URL:myUrl!); request.HTTPMethod=“POST”

NSURLSession.sharedSession().dataTaskWithRequest(request) { (data:NSData?, response:NSURLResponse?, error:NSError?)
    let postString = "userEmail=\(userEmail)&userFirstName=\(userFirstName)&userLastName=\(userLastName)&userPassword=\(userPassword)";

    request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding);

    print(postString)

    NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data:NSData?, response:NSURLResponse?, error:NSError?) -> Void in

        dispatch_async(dispatch_get_main_queue())
            {

                spinningActivity.hide(true)

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


                do {
                    let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary

                    if let parseJSON = json {

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

                        if( userId != nil)
                        {
                            let myAlert = UIAlertController(title: "Mensaje", message: "¡Registro exitoso!", preferredStyle: UIAlertControllerStyle.Alert);

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

                                self.dismissViewControllerAnimated(true, completion: nil)
                            }

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

                        }

                    }

                } catch _ as NSError {



                }

        }

    }).resume()

}