user12180762
user12180762

Reputation:

Unable to deinit in swift using firestore database

I am using the below code for deinit function using firestore database in swift ios, but it is giving me error, I need to use deinit when the table view controller is loaded, please assist, thank you

Error

Cannot invoke 'removeObserver' with an argument list of type '(CollectionReference?)'

Code

fileprivate var _refHandle: CollectionReference!


   deinit {
        if let refHandle = _refHandle {
            self.ref.removeObserver(_refHandle)
           }
    }

Upvotes: 0

Views: 158

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317372

If you're using addSnapshotListener() to attach a listener to a CollectionReference (which is also a Query), note its documented return type. It returns a ListenerRegistration object, and you call its remove() method to stop listening.

Please read the documentation for more details and examples.

Upvotes: 1

Related Questions