发现零致命错误,但打印得很好

时间:2017-10-20 22:48:00

标签: ios swift

我正在尝试使用登录功能,当我切换到swift 4时,我现在收到错误。函数崩溃并发出fatal error: unexpectedly found nil while unwrapping an Optional value错误。但是,当我运行电子邮件和密码传递的print语句时,它会将它们打印出来作为非可选字符串。

以下是我的代码:

@IBAction func Login(sender: AnyObject) {
    let email = self._Email.text!
    let password = self._Password.text!
    print("below is the email")
    print(email)
    print("below is the password")
    print(password)
    FIRAuth.auth()!.signIn(withEmail: email, password: password, completion: { user, error in
        if error == nil {
            //successfull login
            print("Successful login****************************************")

            //performs a segue to the next view controller
            if user!.isEmailVerified{
                //if the email is verified
                let vc = self.storyboard!.instantiateViewController(withIdentifier: "ProfileView") as! ProfileView
                self.present(vc, animated: true, completion: nil)
            }
            else {
                if let errCode = FIRAuthErrorCode(rawValue: error!._code) {

                    switch errCode {
                    case .errorCodeNetworkError:
                        print("There has been a connection error")
                    case .errorCodeInvalidEmail:
                        print("invalid email")
                    case .errorCodeEmailAlreadyInUse:
                        print("in use")
                    default:
                        print("Create User Error: \(error!)")
                        //error with login
                        self.signupErrorAlert(title: "Error", message: "Email or password is not recognized")
                        print ("Login Error**************")
                    }
                }
            }
        }
    })
}

异常发生在以下行:FIRAuth.auth()!.signIn(withEmail: email, password: password, completion: { user, error in

0 个答案:

没有答案