错误是类型'AuthDataResult'的值没有成员'uid'吗? [英] ERROR is value of type 'AuthDataResult' has no member 'uid'?
问题描述
我的代码错误 我不知道为什么说"uid"没有成员,我也不知道AuthDataResult的来源,因为我从未将它用作导入或类似的东西……
My codes error I do not know why its saying that 'uid' has no member, also i don't know where AuthDataResult is coming from because i have never used this as an import or anything along those lines...
@IBAction func signinPressed(_ sender: Any) {
if let email = emailField.text, let password = passwordField.text {
Auth.auth().signIn(withEmail: email, password: password) { (user, error )
in
if error != nil{
//create account
} else {
KeychainWrapper.standard.set((user?.uid)!,
forKey: ("Key_UID"))
self.preformSegue(performSegue(withIdentifier: "toFeed", sender: nil))
}
}
}
}
推荐答案
您收到的错误是:
类型为
AuthDataResult
的值没有成员uid
如果您查看 AuthDataResult
,您会发现这是正确的:该类中没有uid
. uid
属性存在于FIRUser
中,因此您需要使用:
If you look at the reference documentation for AuthDataResult
, you'll see that this is correct: there is no uid
in that class. The uid
property exists in FIRUser
, so you'll want to use:
user?.user.uid
或者为了减少混乱,请为您当前的user
变量命名,使其更匹配:
Or to make it less confusing, give your current user
variable a name that better matches what it is:
Auth.auth().signIn(withEmail: email, password: password) { (authData, error ) in
if error != nil{
//create account
} else {
KeychainWrapper.standard.set((authData?.user.uid)!,
forKey: ("Key_UID"))
self.preformSegue(performSegue(withIdentifier: "toFeed", sender: nil))
}
}
这篇关于错误是类型'AuthDataResult'的值没有成员'uid'吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!