0
votes

I've been reading the FirebaseDatabase iOS documentation and can't seem to find a straight answer on any of the pages. I have an app that places observers on children in the database whose existence is not guaranteed (i.e. a user is deleted and their posts are deleted as well).

Are observers of the form dbRef.child("childId").observe() {} removed (such that their completion block no longer executes) when the child at "childId" is deleted?

If not, is it enough to check for snapshot existence in the completion block and then call db.child("childId").removeAllObservers(). Would this work if the child no longer exists?

1

1 Answers

1
votes

Listeners are not automatically removed when a node is deleted, as the Firebase client has no way of knowing what condition your code is waiting for.

If you want to remove the listener when the node has been deleted, you'll indeed have to explicitly detach the listener when that condition is met.

Calling removeAllObservers() on the same reference should work. If you have any problems with that, post a question with the minimum, complete/standalone code that reproduces where you got stuck.