是否有可能在firestore查询上有完成块?
问题描述:
我目前有数据的查询试图找到与某个用户名的用户的数据库的FireStore参考。我得到用户后,我想尝试登录。但是,我注意到,查询用户的代码块,一旦被调用就会返回。有没有办法添加完成块或至少停止该程序,直到完成查询。是否有可能在firestore查询上有完成块?
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数据库的图像 https://i.stack.imgur.com/hI1iY.png
答
你需要把你的signIn
内getDocuments
处理器,可能是for
循环之后?
+0
谢谢,我现在觉得有点愚蠢,我看到了答案。 –
+0
我认为每个人在开始使用异步代码时都会犯这种错误至少一次。 –
已经有*是*在代码完成块:这就是你环比'卡.documents'?正如Josh回答的那样,您需要将'Auth.auth()。signIn'代码**移动到**回调块中。 –