gpt4 book ai didi

ios - FirebaseDatabase - removeAllObservers() - 它实际上删除了什么?

转载 作者:行者123 更新时间:2023-11-30 12:02:36 26 4
gpt4 key购买 nike

removeAllObservers() 是否删除其调用的 DatabaseReference 实例的所有观察者,或指定路径上的任何引用?

例如:

MainController.swift

let ref = Database.(...).child("foo/bar").observe(.value, with: handler)



ItemController.swift

public var ref2: DatabaseReference?

public func someMethod() {
self.ref2 = Database.(...).child("foo/bar").observe(.value, with: handler2)
}

override func viewDidDisappear() {
self.ref2?.removeAllObservers()
}

来自 MainControllerref 是否仍会观察 foo/bar 路径,或者该观察者也将被删除?

最佳答案

根据documentation :

If multiple listeners have been added to a database reference, each listener is called when an event is raised. In order to stop syncing data at that location, you must remove all observers at a location by calling the removeAllObservers method.

Calling removeObserverWithHandle or removeAllObservers on a listener does not automatically remove listeners registered on its child nodes; you must also keep track of those references or handles to remove them.

因此,换句话说,您需要将它们全部删除,它们不会自动删除,并且 MainController 中的 ref 仍然会观察到。

关于ios - FirebaseDatabase - removeAllObservers() - 它实际上删除了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47027895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com