As everyone knows when using the awesomeness that is Firebase in iOS,
whenever you have observations in a view controller,,
var o: DatabaseReference?
var o2: DatabaseReference?
var o3: DatabaseReference?
it's essential that when that screen goes away, you must terminate all the observations...
private func clearObservations() {
print("\n\n clearing observations! \n\n")
if o != nil {
o?.removeAllObservers()
o = nil
}
if o2 != nil {
etc...
}
However!
After considerable testing, you cannot call clearObservations()
in deinit
- you must call it in viewDidDisappear
(or some other logical place).
Again - it explicitly does not work in deinit
.
My question, why would it be that actually this does not work in deinit
?
BTW, you fire up a Firebase observor like this:
say, viewWillAppear#
o = Database.database().reference(withPath: "string")
o!.observe(.value, with: { (snapshot) in
self.blah(snapshot)
})