gpt4 book ai didi

ios - 如何在数据快照中提取节点的子节点

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

我的 firebase 设置是这样的:

Parent_node:{
Type:{
1476663471800:{ //This is a timestamp = Int64(date.timeIntervalSince1970 * 1000.0)
uid: USERS_UID;
}
}
}

我将如何访问用户 uid?我试过下面的代码,但它没有提取 UID

self.databaseRef.child("Parent_node/\(Type)").queryLimitedToLast(5).observeEventType(.Value, withBlock: { (snapshot) in

print(snapshot)
if let userDict = snapshot.value as? [String:AnyObject]{
for each in userDict{
let uidExtraced = each
print(uidExtraced)
//("1476663471700", [uid: USERS_UID])

最佳答案

首先使用 snapshot.value?.allValues 获取值然后解析它...

  if snapshot.exists() {
for value in (snapshot.value?.allValues)!{
print(value) // you get [uid: USERS_UID] here

// ... parse it to get USERS_UID
print("user_id -- \(value["uid"])")
}
}

With this method, order of child might be different. For ordered nodes, you can use snapshot.child

关于ios - 如何在数据快照中提取节点的子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40078420/

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