如何在Swift中观察下面的GeoFire句柄?

这是Swift,Firebase和Geofire的问题。

我想知道如何在Swift中为下面的观察者删除一个GeoFire句柄。

locationsEnd!.query(at: location, withRadius: 16.0).observe(GFEventType.init(rawValue: 0)!, with: {(key, location) in 

以下工作正常(在viewDidDisappear):

 locationsEnd?.firebaseRef.removeAllObservers() 

然而,处理它不:

 var locationHandle: UInt = 0 override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) //following does not work: locationsEnd?.firebaseRef.removeObserver(withHandle: locationHandle) } func aroundMe(_ location: CLLocation){ locationHandle = locationsEnd!.query(at: location, withRadius: 16.0).observe(GFEventType.init(rawValue: 0)!, with: {(key, location) in //etc }) } 

我已经尝试了locationHandle如下,没有成功:

 var locationHandle = FirebaseHandle() var locationHandle: FirebaseHandle = 0 var locationHandle: UInt! var locationHandle: UInt = 0 var locationHandle = FIRDatabaseHandle() var locationHandle: FirebaseHandle = 0 

任何build议将是伟大的,如上所述,我可以删除所有的观察员,但在其他地方我需要删除一个句柄。

locationHandle被定义为代码中的一个UInt,它需要是FIRDatabaseHandle

以下是删除Firebase句柄的示例

 var myPostHandle : FIRDatabaseHandle? func someFunc() { myPostHandle = ref.child("posts").observeEventType(.childAdded, withBlock: { (snapshot) -> Void in let postBody = snapshot.value!["body"] as! String }) } func stopObserving() { if myPostHandle != nil { ref.child("posts").removeObserverWithHandle(myPostHandle) } } 

GeoFire更像这样

 let geofireRef = FIRDatabase.database().reference() let geoFire = GeoFire(firebaseRef: geofireRef) let center = CLLocation(latitude: 37.7832889, longitude: -122.4056973) var circleQuery = geoFire.queryAtLocation(center, withRadius: 0.6) var queryHandle = circleQuery.observeEventType(.KeyEntered, withBlock: { (key: String!, location: CLLocation!) in //do something }) 

然后删除,使用

 circleQuery.removeObserverWithFirebaseHandle(queryHandle)