func addUserObserver(_ update: @escaping () -> Void) {
FriendSystem.system.USER_REF.addSnapshotListener { snapshot, error in
self.userList.removeAll()
guard error == nil else {
print("Error retreiving collection")
return
}
for document in snapshot!.documents {
let email = document.get("email") as! String
if email != Auth.auth().currentUser?.email! {
self.userList.append(User(userEmail: email, userID: document.documentID))
}
update()
}
}
}
I have added a listener but can't figure out how to disconnect/remove it. Thanks!
As shown in the documentation on detaching a listener, you need to keep the value you get back from addSnapshotListener:
var listener = FriendSystem.system.USER_REF.addSnapshotListener { snapshot, error in
...
And then later you can remove the listener with:
listener.remove()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With