Pau*_*eau 1 ios firebase swift firebase-realtime-database
我正在寻找Firebase数据库中某个部分的所有子项的名称。然后,我想将它们放在一个数组中。
{
"sVkyFjTI9yOTlOPFzUv5MvFozlh2" : {
"groups" : {
"group 1" : "9FA02017-172B-434B-A873-518854697CCC",
"group 2" : "B52743E0-8441-40FB-98BA-51920F31EFE6",
"group 3" : "1A320965-88A3-42FF-A917-0D93BE39B357"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经做到了:
ref.child("user_profile").child(user!.uid).child("groups/").observeSingleEventOfType(.Value, withBlock: { snapshot in
if !snapshot.exists() { return }
let groupDict = snapshot.value! as? [string]
})
Run Code Online (Sandbox Code Playgroud)
但是我只需要数组中的子名称(在这里:“组1”,“组2”,“组3”),而不需要它们的值。谢谢您的帮助。
我使用了这段代码,它的工作原理非常完美:var ref = Firebase(url:“ https://.firebaseio.com/restaurants/”)
ref.child("user_profile").child(user!.uid).child("groups").observeEventType(.Value, withBlock: {
snapshot in
var groupNames = [String]()
for group in snapshot.children {
groupNames.append(group.key)
}
print(groupNames)
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1156 次 |
| 最近记录: |