问题
I am setting up a login page with Firebase and I've run into an error where uid
isn't getting recognized. Here's my code:
FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (FIRUser,error) in
if error != nil {
print(error)
return
}
guard let uid = user?.uid else {
return
}
I also can't command-click into FIRUser
, however if I get rid of the guard statement, authentication works perfectly fine.
I have Firebase and FirebaseDatabase imported (can't import FirebaseAuth, it's crossed out), so it's not that.
Any idea why I can't access FIRUser
and use uid
?
回答1:
You need to create the variable user
inside your closure. Rewrite your function to this instead.
FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user: FIRUser?, error: Error?) in
if error != nil {
print(error)
return
}
guard let uid = user?.uid else {
return
}
来源:https://stackoverflow.com/questions/40386771/type-user-had-no-member-uid-swift-3-firebase