我是Swift的新手,我正在使用Firebase制作一个非常简单的登录页面。我有以下代码:
guard fullNameTextField.text != "", emailTextField.text != "", passwordTextField.text != "", confirmPasswordTextField.text != ""
else {
return
}
}
if passwordTextField.text == confirmPasswordTextField.text {
//MARK: Firebase autenthication
FIRAuth.auth()?.createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion:{
(user,error)in
if let error = error {
print(error.localizedDescription)
}
并且Xcode表示存在期望的声明错误。如果有人可以帮助我,我会很感激,因为我想我已经尽了一切。
答案 0 :(得分:0)
我认为您需要更新到最新版本
Auth.auth().createUser(withEmail: email, password: password) { (authResult, error) in
// ...
guard let user = authResult?.user else { return }
}
在这里Docs
答案 1 :(得分:0)
您应避免强行打开包装。您的代码应如下所示:
guard let name = fullNameTextField.text, name.count > 0 else { return }
guard let email = emailTextField.text, email.count > 0 else { return }
guard let password = passwordTextField.text, password.count > 0 else { return }
guard let confirmPassword = confirmPasswordTextField.text, confirmPassword.count > 0 else { return }
if password == confirmPassword {
Auth.auth().createUser(withEmail: email, password: password, completion: { (result, error) in
if let error = error {
print("Failed to create new user", error)
return
}
print("Successfully created user:", result?.user.uid ?? "")
})
}