我目前有一个 Firestore 数据库引用,它查询数据以尝试找到具有特定用户名的用户。获得用户后,我想尝试登录。但是,我注意到查询用户的代码块在调用后立即返回。有什么方法可以添加完成 block 或至少停止程序直到完成查询。
u.name = name
global.db.collection("users").whereField("username", isEqualTo: u.name).getDocuments(completion: { (snap, error) in
if error != nil {
print(error?.localizedDescription as Any)
return
}
for doc in (snap?.documents)! {
u.email = doc.data()["email"] as! String
}
})
Auth.auth().signIn(withEmail: u.email, password: password, completion: { (user, error) in
if error != nil {
print(error?.localizedDescription as Any)
return
}
print("Succesfully Logged In")
self.toListSelector(user: u)
})
这是我的 Firestore 数据库图像的链接 /image/hI1iY.png
最佳答案
您需要将 signIn
放在 getDocuments
处理程序中,可能在 for
循环之后?
关于swift - 是否可以在 firestore 查询上有一个完成 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47487678/