gpt4 book ai didi

Swift & Firebase 无法将类型 'AuthDataResult?' 的值分配给类型“用户?

转载 作者:行者123 更新时间:2023-11-28 11:35:05 25 4
gpt4 key购买 nike

我正在重新访问一个旧应用程序,但在开发新功能之前,我想修复所有错误。我不确定这是由较新的 Swift 语法还是 Firebase 的更新(或两者)引起的,但以前有效的代码现在导致了 2 个错误。

var user = Auth.auth().currentUser


Auth.auth().createUser(withEmail: theEmail, password: thePassword, completion: { (user, error) in
if let theError = error {

var errMessage = "An unknown error occured."
if let errCode = AuthErrorCode(rawValue: (theError._code)) {
switch errCode {

case .invalidEmail:
errMessage = "The entered email does not meet requirements."
case .emailAlreadyInUse:
errMessage = "The entered email has already been registered."
case .weakPassword:
errMessage = "The entered password does not meet minimum requirements."
default:
errMessage = "Please try again."
}
}
completion(nil, errMessage)
} else {
self.user = user
completion(user, nil)
}
})

self.user = user 上,错误消息是 Cannot assign value of type 'AuthDataResult?'键入“用户?”

completion(user, nil) 时,错误消息是 Cannot convert value of type 'AuthDataResult?'到预期的参数类型“用户?”

有人能解释一下为什么这个曾经有效的代码不再有效以及我可以做些什么来使其达到当前的期望

最佳答案

替换

self.user = user

Auth.auth().createUser(withEmail: theEmail, password: thePassword, completion: { (authData, error) in

.....

if let res = authData?.user {
self.user = res
}

}

关于Swift & Firebase 无法将类型 'AuthDataResult?' 的值分配给类型“用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55621777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com