不知道为什么会这样。希望我能得到第二或第三双眼睛。请参阅代码中的注释。代码如下:
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 控制台给了我这个:
有什么想法吗?
答案 0 :(得分:0)
我在测试功能时有一个指向 3 个不同文档 ID 的集合。我有一个快照但返回零,因为数据库对返回的内容感到困惑。谢谢,弗兰克,与我们联系!