我正在从用户对象下载chatID,然后在每个下载的聊天对象上附加一个childChanged
侦听器。
如何获取快照中收到的孩子的父密钥?
我需要父键,以便可以跟踪每次聊天中附加的每个侦听器。
var currentUserChats = [Chat]() {
didSet(newChat){
attachChildChangedObserverOn(chat: newChat)
}
}
var observersArray = [String: UInt]() // chatUID:handle
func attachChildChangedObserverOn(chat: Chat) {
var handle: UInt = 0
let ref = DDatabaseRReference.chats.reference().child(chat.chatUID)
handle = ref.observe(.childChanged, with: {[weak self] (snapshot) in
//how can I get the parent key?
//let chatUID = snapshot.parentKey
self?.observersArray[chatUID] = handle
)}
}
chats
-LOTqZNaOfarrlTYTKo4
chatImageUID: ""
chatUID: "-LOTqZNaOfarrlTYTKo4"
isGroupChat: false
users
0Y0l7gJbGgM5l2XKW25DrEZqMPV2
name: "Alex"
lastMessage: "bla bla"