Swift 4:无法将类型()的值转换为预期的参数类型

Swift 4:无法将类型()的值转换为预期的参数类型,swift,xcode,Swift,Xcode,我是swift的新手,似乎无法通过此错误: /用户/me/code/Apps/Aero-Eco/Aero-Eco/Controller/ViewController.swift:36:109: 无法将类型为“()”的值转换为所需的参数类型 “((UIAlertAction)->Void”?” 这是触发它的代码 @IBAction func loginPressed(_ sender: Any) { Auth.auth().signIn(withEmail: emailTextF

我是swift的新手,似乎无法通过此错误:

/用户/me/code/Apps/Aero-Eco/Aero-Eco/Controller/ViewController.swift:36:109: 无法将类型为“()”的值转换为所需的参数类型 “((UIAlertAction)->Void”?”

这是触发它的代码

@IBAction func loginPressed(_ sender: Any) {

        Auth.auth().signIn(withEmail: emailTextField.text!, password: passwordTextField.text!) { (user, error) in

            if error != nil {
                print(error!)

                let alert = UIAlertController(title: "Error", message: "Those credentials are not recognized.", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: self.clearLogin()))
                self.present(alert, animated: true, completion: nil)

            } else {
                print("Log in successful!")
                self.clearLogin()
                self.performSegue(withIdentifier: "goToSwitchboard", sender: self)
            }
        }
    }

func clearLogin() {
        self.emailTextField.text! = ""
        self.passwordTextField.text! = ""
    }
试试这个

alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler:{(action) in self.clearLogin()}))

这就是为什么。您必须在

    let okAction = UIAlertAction(title: "OK".localized, style: .default, handler: {

      (action) in//added this line 
self.clearLogin()
    })