【发布时间】:2020-08-10 13:23:03
【问题描述】:
我使用 Firestore 创建了一个用户,但我无法将其保存到结构中以便稍后获取用户的名字作为标签。我该如何解决?
//create the user
Auth.auth().createUser(withEmail: email, password: password) { (result, err) in
print(result)
//check for errors
if err != nil {
//there was an error while creating user
self.showError("Error creating user")
}//end if
else {
//user was created successfully, store name, last name and email
let db = Firestore.firestore()
db.collection("users").addDocument(data: ["firstName": firstName, "lastName": lastName, "age": age!, "imageUrl": imageUrl, "email": email, "uid": result!.user.uid]) { (error) in
if error != nil {
//show error message
self.showError("Account created, but database couldn't save name")
}//end of if
}//end of db collection
//save current user
//This is where I would like to save my user to my struct
//transition to homescreen
self.transitionToTabBarVC()
}//end else
}//end of create user
【问题讨论】:
-
将结构体转换为类,类是引用类型。不同于具有价值的结构
标签: swift google-cloud-firestore firebase-authentication