打印特定的子firebase数据库

时间:2017-04-01 01:53:31

标签: swift firebase firebase-realtime-database

我有以下数据库布局:

-PGroups
   -Date
      -GameTime
         -Entry Cost

我知道您可以使用以下内容打印PGroups中的所有内容

ref.child("PGroups").observeSingleEventOfType(.Value, withBlock: { (snapshot) in

                    //makes sure there are public
                    if (snapshot.hasChildren()){
                        print(snapshot.childrenCount) // I got the expected number of items
                        let enumerator = snapshot.children
                        while let rest = enumerator.nextObject() as! FIRDataSnapshot {
                            print(rest.value)
                        }

有没有办法打印出#34; GameTime"平等孩子,或只是"日期"儿?

1 个答案:

答案 0 :(得分:0)

您可以尝试从数据的子项中创建字典,这可能会起作用。

ref.child("PGroups").observeSingleEventOfType(.Value, withBlock: { (snapshot) in

   if let snapValue = snapshot.value as [String : [String : String]]{
      // Here try printing out the dictionary and seeing how to correctly get the right value out.
   }

我对您的数据库结构有点困惑,但如果这不起作用,您可能必须创建一个更深层次的字典,即[String : [String : [String : String]]]。如果你给出一个更详细的结构图片,我可以更好地帮助你获得你想要的价值。