@IBAction func signUpButton_TouchUpInside(_ sender: Any) {
if !isValidEmailAddress(emailAddressString: emailTextField.text!) {
self.signUpErrorLabel.text = "Please enter a valid email address."
}
Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text! , completion: {
(user: User?, error: Error?) in
let err = NSError()
if Error.self != nil {
self.signUpErrorLabel.isHidden = false
if Error?.localizedDescription == "This email is already in use." {
self.signUpErrorLabel.text = "That email is already in use."
}
}
else {
self.signUpErrorLabel.isHidden = true
self.performSegue(withIdentifier: "welcomeSegue", sender: nil)
let uid = user?.uid
let storageRef = Storage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("Profile Image").child(uid!)
if let profileImg = self.selectedImage, let imageData = UIImageJPEGRepresentation(profileImg, 0.1) {
storageRef.putData(imageData, metadata: nil, completion: {
(metadata, error) in
if error != nil {
}
let profileImageUrl = metadata?.downloadURL()?.absoluteString
self.setUserInformation(email: self.emailTextField.text!, uid: uid!,profileImgUrl: profileImageUrl! )
})
}
self.setUserInformation(email: self.emailTextField.text!, uid: uid!, profileImgUrl: " ")
}
})
}
这是我上面的代码。当我尝试运行它时,它给了我一个错误:
输入'错误?'没有成员'localizedDescription'“。
答案 0 :(得分:1)
使用error
(传递给闭包的变量),而不是Error
(一种类型):
Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text! , completion: { user, error in
if let error = error {
self.signUpErrorLabel.isHidden = false
if error.localizedDescription == "This email is already in use." {
self.signUpErrorLabel.text = "That email is already in use."
}
return
}
...
}