如何解决从 Firestore 侦听器返回零快照文档
不知道为什么会这样。希望我能得到第二或第三双眼睛。请参阅代码中的注释。代码如下:
import Foundation
import Firebase
class FollowerApi {
func loadFollowers(onSuccess: @escaping(_ followers: [Follower]) -> Void,newFollower: @escaping(Follower) -> Void,deleteFollower: @escaping(Follower) -> Void,listener: @escaping(_ listenerHandle: ListenerRegistration) -> Void) {
guard let userId = Auth.auth().currentUser?.uid else { return }
let listenerFirestore = Ref.FIRESTORE_COLLECTION_MY_FOLLOWERS.document(userId).collection("followers").order(by: "date",descending: false).addSnapshotListener { querySnapshot,error in
guard let snapshot = querySnapshot else { return }
// this (snapshot.documentChanges.forEach) is where I am not
// returning any documents! The breakpoint skips the switch
// statement and hits the listener at the bottom of the file.
snapshot.documentChanges.forEach { documentChange in
switch documentChange.type {
case .added:
var followers = [Follower]()
let dict = documentChange.document.data()
guard let decodedFollower = try? Follower.init(fromDictionary: dict) else {
return
}
newFollower(decodedFollower)
followers.append(decodedFollower)
onSuccess(followers)
case .modified:
print("type: modified")
case .removed:
print("type: removed")
let dict = documentChange.document.data()
guard let decodedFollower = try? Follower.init(fromDictionary: dict) else {
return
}
deleteFollower(decodedFollower)
}
}
}
listener(listenerFirestore)
}
}
我可以设置数据并将其发送到数据库,我可以看到我在那里清楚地有一个文档。但是 Xcode 控制台给了我这个:
有什么想法吗?
解决方法
已解决
我在测试功能时有一个指向 3 个不同文档 ID 的集合。我有一个快照但返回零,因为数据库对返回的内容感到困惑。谢谢,弗兰克,与我们联系!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。