当我在location-> here-> users上检查firebase时,每个用户都有姓名和其他信息,并且每个用户都有一个集合(称为“消息”)。但是,当我使用下面的函数加载消息时,for循环甚至无法运行,并且print语句显示我的snapshotDocuments为空。在此之前,我具有完全相同的loadMessages函数,但我的位置只是消息,而不是location-> here-> users(具有其他信息,然后有子集合“ messages”),并且可以工作(即,数组不存在) 。这是我遇到错误的新数据库格式的屏幕截图。我真的很感激调试中的任何帮助。谢谢!
func loadMessages() {
db.collection("location").document("here").collection("users").document(Auth.auth().currentUser?.uid ?? "").collection("messages").order(by: "date").addSnapshotListener { (querySnapshot, error) in
self.messages = []
if let e = error {
print("There was an issue retrieving data from Firestore. \(e)")
} else {
if let snapshotDocuments = querySnapshot?.documents {
self.count = 0
print("QUERY::::: \(snapshotDocuments)")
for doc in snapshotDocuments {
if (self.count == 0){
self.count = 1
self.messages = []
let newMessage = Message(sender: "me", body: "", deleteThis: "")
self.messages.append(newMessage)
}
. . . . (other parts of the code aren't relevant)