【发布时间】:2018-01-07 20:19:38
【问题描述】:
我刚刚为 Firebase 升级了我的 Xcode 项目中的 pod 文件,它显示了一堆错误。注册用户时出现错误Cannot convert value type "User?" to expected argument type "User!"
我不确定是什么问题。我尝试更改一些可选值以使其正常工作,但我似乎不太了解问题所在。
这是我有错误的函数:
代码已修改为我的问题的解决方案
import Firebase
// Sign Up Function
func signUp(username: String, name: String, email: String, password: String){
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
if error == nil {
self.setUserInfo(user: user, username: username, name: name, email: email, password: password)
}
else{
print(error?.localizedDescription as Any)
}
})
}
// Set the user info to Firebase storage. username, and password
private func setUserInfo(user: Firebase.User!, username: String, name: String, email: String, password: String){
if error == nil {
self.saveUserInfo(user: user, username: username, name: name, password: password)
}
else{
print(error?.localizedDescription as Any)
}
}
编辑:
正如用户 ryanwils 所说,无论我在哪里使用 FIRUser,都需要替换为 Firebase.User
这里有一个指向迁移指南的链接,进一步解释了这一点:https://firebase.google.com/docs/reference/ios/naming-migration-guide
请注意,代码已更新,因此截至本次编辑当天没有出现错误
【问题讨论】:
-
试试这个:self.setUserInfo(user: user!, username: username, name: name, email: email, password: password)
-
@Bruno Recillas 您的用户对象不是可选的。尝试更改为用户?
-
@OMK 我之前试过了,还是一样的错误/:
-
@TusharSharma 当我这样做时,它告诉我
Optional chain has no effect, expression already produces "User?" -
如果你不提供任何类型只是给用户。
标签: ios swift firebase swift3 firebase-authentication