我懷疑我的代碼有問題,我無法確定我在這裏做錯了什麼。錯誤在這裏:self.setUserInfo(firstLastName: firstLastName, user: user, username: username, location: location, biography: biography, password: password, pictureData: pictureData)
這是我的signUp功能。無法轉換'User?'類型的值到期望的參數類型'用戶!'
func signUP(firstLastName: String, username: String, email: String, location: String, biography: String, password: String, pictureData: NSData!) {
Auth.auth().createUser(withEmail: email, password: password) { (user, error) in
if error == nil{
self.setUserInfo(firstLastName: firstLastName, user: user, username: username, location: location, biography: biography, password: password, pictureData: pictureData)
}else{
print(error?.localizedDescription)
}
}
}
private func setUserInfo(firstLastName: String, user: User!, username: String, location: String, biography: String, password: String, pictureData: NSData!){
let imagePath = "profileImage\(user.uid)/userPic.jpg"
let imageRef = storageRef.child(imagePath)
let metaData = StorageMetadata()
metaData.contentType = "image/jpeg"
imageRef.putData(pictureData as Data, metadata: metaData){(newMetaData, error)
in
if error == nil{
let changeRequest = User.createProfileChangeRequest()
changeRequest.displayName = username
if let photoURL = newMetaData!.downloadURL(){
changeRequest.photoURL = photoURL
}
changeRequest.commitChanges(completion: { (error) in
if error == nil{
self.saveUserInfo(firstLastName: firstLastName, user: user, username: username, location: location, biography: biography, password: password)
print("user info set")
}else{
print(error?.localizedDescription)
}
})
}else{
print(error?.localizedDescription)
}
}
}
展會實現Auth.auth()的createUser(withEmail的':'方法 – D4ttatraya
什麼是您的用戶類的樣子 – Torewin