问题
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))
}
}
}
}
回答1:
The error you get is:
Value of type
AuthDataResult
has no memberuid
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
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))
}
}
来源:https://stackoverflow.com/questions/51977775/error-is-value-of-type-authdataresult-has-no-member-uid