线程1致命错误可选值Swift

时间:2018-05-21 15:05:26

标签: swift multithreading

@IBAction func login(_ sender: Any) {
    guard emailField.text != "", passField.text != "" else {return}

    Auth.auth().signIn(withEmail:emailField.text!,password:passField.text!, completion: { (user, error) in
        if let error = error {
            print(error.localizedDescription)

我收到此错误:

  

线程1:致命错误:在展开Optional值时意外发现nil。

1 个答案:

答案 0 :(得分:0)

尝试:

    guard let email = self.emailField.text, let password = self.passField.text else { return }
    if email != "" && pass != "" {
        Auth.auth().signIn(withEmail: email, password: password) { (user, err) in
            if err != nil { print(err.localizedDescription); return }

            // do something

        }
    }