当我的代码在这里时,我在处理firestore查询时遇到问题
let wallpaperRef = Firestore.firestore().collection("wallpaper").order(by: "noOfDownloads", descending: true)
wallpaperRef.getDocuments(completion: { (snap, error) in
if error == nil {
print(snap)
}
})
现在这个查询的输出就是这个
Optional(<FIRQuerySnapshot: 0x600000070640>)
Optional(<FIRQuerySnapshot: 0x600000070640>)
Optional(<FIRQuerySnapshot: 0x6000000705c0>)
我想接受这个查询并获取数据,无论init是可读形式
如果对集合运行查询,则得到的结果是包含(可能)多个文档的QuerySnapshot
。要获取每个文档,您需要循环结果。来自Firebase documentation on reading multiple documents:
db.collection("cities").whereField("capital", isEqualTo: true)
.getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
print("\(document.documentID) => \(document.data())")
}
}
}
所以你的代码只是缺少来自qazxsw i块的循环。就像是:
else