嗨,我迫切需要一些帮助
所有这些都发生在UIViewController子类
中我目前正在附加侦听器并填充数组,然后将其提供给以下函数中的UICollectionView(原谅一些截断代码):
fileprivate func fetchNotes() { // This function is called in vidDidLoad()
let db = Firestore.firestore()
// Attaching listener (ie. listener is an attribute of the class)
listener = db.collection("Courses").document(titleForNavBar).collection("Notes")
.addSnapshotListener { snapshot, error in
// checking for any error
if error != nil {
self.arrayOfNotes.removeAll()
self.allNotesView.arrayOfNotes = self.arrayOfNotes
DispatchQueue.main.async {
self.allNotesView.allNotesCollectionView.reloadData()
}
return
} else {
self.arrayOfNotes.removeAll()
// if there is no error, the array holding all the objects is populated, in a for..loop
for document in (snapshot?.documents)! {
if let noteName = document.data()["noteName"] as? String,
let lectureInformation = document.data()["lectureInformation"] as? String,
let noteDescription = document.data()["noteDescription"] as? String,
let forCourse = document.data()["forCourse"] as? String,
let storageReference = document.data()["storageReference"] as? String,
let noteSize = document.data()["noteSize"] as? Int,
let rating = document.data()["rating"] as? Int
{
self.arrayOfNotes.append(Note(forCourse: forCourse, lectureInformation: lectureInformation, noteDescription: noteDescription, noteName: noteName, noteSize: noteSize, rating: rating, storageReference: storageReference))
self.allNotesView.arrayOfNotes = self.arrayOfNotes
// reloading the UICollectionView (on the main thread) so that it displays new data
DispatchQueue.main.async {
self.allNotesView.allNotesCollectionView.reloadData()
}
}
}
}
}
}
当视图消失时,我也会删除监听器
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(true)
if listener != nil {
listener.remove()
}
print("listener removed")
}
当我第一次在任何设备或模拟器上安装应用程序时,这很好用。当我尝试启动控制器时,第二次,我得到一个非常讨厌的错误,我不知道如何调试。
为准确起见,控制台会抛出此错误:
NoteShare [97230:10528984] ***断言失败 - [FSTLevelDBRemoteDocumentCache decodingMaybeDocument:withKey:],third_party / firebase / ios / Source / Firestore / Source / Local / FSTLevelDBRemoteDocumentCache.mm:152
我知道这个问题很长(对不起),但你们有没遇到这个错误。请提供一些如何解决此问题的提示。谢谢!如果您需要查看我的任何其他代码,请告诉我。