gpt4 book ai didi

ios - 如何确定 swift firebase 节点是否更新

转载 作者:行者123 更新时间:2023-11-30 12:05:28 25 4
gpt4 key购买 nike

我正在观察 firebase 中的节点是否已更新,以便我可以重新加载表中的数据。我有这段代码观察节点,但我找不到任何关于如何检查节点值是否已更改的具体内容。

观察 firebase 中的“info”节点:

for activeGrp in FriendSystem.system.activeGroups {
FriendSystem.system.CURRENT_USER_GROUP_REF
.child(activeGrp.groupID)
.child("info")
.observe(.value, with: {
(snapshot) in
//This is where I am lost/////////////////
})
}

组数组

var activeGroups = [Groups]()

func addActiveGroupObserver(_ update: @escaping () -> Void) {
CURRENT_USER_GROUP_REF.observe(.value, with: { (snapshot) in
self.activeGroups.removeAll()
for child in snapshot.children.allObjects as! [DataSnapshot] {
let id = child.key
self.getGroup(id, completion: { (group) in
self.activeGroups.append(group)
self.activeGroups.sort {$0.name < $1.name}
update()

})

}
if snapshot.childrenCount == 0 {
update()
}
})
}

Firebase 节点 enter image description here

最佳答案

您必须使用 FIRDataEventTypeChildChanged

监听列表中项目的更改。每当修改子节点时都会触发此事件。这包括对子节点的后代的任何修改。传递给事件监听器的快照包含子级的更新数据。

有关详细说明,请使用以下 URL。

https://firebase.google.com/docs/database/ios/lists-of-data

关于ios - 如何确定 swift firebase 节点是否更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46723565/

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