Ios 什么';类型';removeObserverWithHandle的Firebase句柄是否应该在Swift中?

Ios 什么';类型';removeObserverWithHandle的Firebase句柄是否应该在Swift中?,ios,swift,firebase,Ios,Swift,Firebase,我应该将“observer”句柄初始化为什么 我现在做的是:var句柄:UInt?,对吗?它应该是UInt类型还是其他类型 另外,在函数viewwillEnglish中,我会在移除句柄之前检查句柄是否为nil if handle != nil { // Remove the observer playerRef.child(ID).removeObserver(withHandle: handle!) } 通过这样做,移除观察者是否从以下位置将句柄设置为nil?

我应该将“observer”句柄初始化为什么

我现在做的是:
var句柄:UInt?
,对吗?它应该是
UInt
类型还是其他类型

另外,在函数
viewwillEnglish
中,我会在移除句柄之前检查句柄是否为nil

if handle != nil {        
    // Remove the observer
    playerRef.child(ID).removeObserver(withHandle: handle!)
}
通过这样做,移除观察者是否从以下位置将
句柄设置为nil?

将回调块添加到引用时,将返回
FIRDatabaseHandle
。这些句柄可用于删除回调块

传递给
removeObserver(withHandle:)
的句柄是添加该观察者时返回的值。它属于
数据库句柄类型
,因此:

var refHandle: DatabaseHandle!
从同一文档页面中可以看到如何使用它的示例:

因此,您可以使用
refHandle
删除该侦听器:

postRef.removeObserver(withHandle: refHandle)
发件人:


我理解这一部分,但refHandle声明为什么?例如,变量refHandle=!?还有一个不同的问题,我是否在viewcontroller中创建了观察者。用户点击“主页”按钮,应用程序不会自动切换到后台。观察者是否仍在获取实时数据?!据我所知,点击“主页”按钮不会调用
viewdidegase
func。那么我应该如何移除句柄呢?我找到了第一部分的答案,我应该使用
var-refHandle:DatabaseHandle
postRef.removeObserver(withHandle: refHandle)
/**
 * A FIRDatabaseHandle is used to identify listeners of Firebase Database events. These handles
 * are returned by observeEventType: and can later be passed to removeObserverWithHandle: to stop
 * receiving updates.
 */
typedef NSUInteger FIRDatabaseHandle NS_SWIFT_NAME(DatabaseHandle);