Swift-未识别.childchanged上的Firebase观察器

Swift-未识别.childchanged上的Firebase观察器,swift,firebase,firebase-realtime-database,Swift,Firebase,Firebase Realtime Database,下面是代码,即使我通过应用程序或直接在Firebase中更改Firebase中名为“tokens”的子节点,它也不会执行 handle = ref.child("Users").child(uid).child("tokens").observe(.childChanged, with: { snap in print("Changed Token Count: ", snap.value!) if snap.value is

下面是代码,即使我通过应用程序或直接在Firebase中更改Firebase中名为“tokens”的子节点,它也不会执行

handle = ref.child("Users").child(uid).child("tokens").observe(.childChanged, with: { snap in

                print("Changed Token Count: ", snap.value!)

                if snap.value is NSNull {

                    // Child not found

                } else {

                    if (currTokenCount < snap.value as! UInt) {

                        print("Value increased....")

                    } else {

                        print("Value decreased....")

                    }

                }

            }) { (error) in

                print(error.localizedDescription)

            }
handle=ref.child(“用户”).child(uid).child(“令牌”).observe(.childChanged,带:{snap-in
打印(“已更改的令牌计数:”,snap.value!)
如果snap.value为空{
//未找到子对象
}否则{
if(currtokentcount
我假设您的数据结构如下:

Users
  uid1
    tokens: "value of tokens"
如果要侦听对上述结构中特定用户的
标记的更改,请使用
.value
侦听器:

handle = ref.child("Users").child(uid).child("tokens").observe(.value, with: { snap in

    print("Changed Token Count: ", snap.value!)

    if snap.value is NSNull {
        // Child not found
    } else {
        if (currTokenCount < snap.value as! UInt) {
            print("Value increased....")
        } else {
            print("Value decreased....")
        }
    }
}) { (error) in
    print(error.localizedDescription)
}

啊。。。。非常感谢,我正在使用
.value
但我认为
.childchanged
会减少活动,但感谢您告知我
.childchanged
的工作原理!!!快速提问如果我有
var句柄:UInt=0
,我想看看它是否为空,下面的代码会抛出一个警告<代码>如果句柄!=空
。我错过什么了吗?我正在使用
handle
删除观察者。@FrankvanPuffelen感谢您解释.value和.childChanged之间的区别!
Users
  uid1
    tokens
      token1: "value of token1"
      token2: "value of token2"