How do I loop all Firebase children at once in the same loop?

后端 未结 2 1565
天命终不由人
天命终不由人 2021-01-24 21:07

I have three nodes in firebase that I would like to loop through using the same loop. I\'m successfully able to loop through a single node (cookies) using this code:

<         


        
2条回答
  •  故里飘歌
    2021-01-24 22:01

    The following code prints all three levels of snapshots. I hope this will help:

    self.databaseRef.child("cookies").observeSingleEvent(of: .value, with: { (cookiesSnapshot) in
        print("cookies snapshot: \(cookiesSnapshot)")
    
        self.databaseRef.child("dessert").observeSingleEvent(of: .value, with: { (dessertSnapshot) in 
            print("dessert snapshot: \(dessertSnapshot)")
    
            self.databaseRef.child("breakfast").observeSingleEvent(of: .value, with: { (breakfastSnapshot) in
                print("breakfast snapshot: \(breakfastSnapshot)")
            })
        })
    })
    

    I can't check this, so I hope all the } and ) are at the right place. :)

提交回复
热议问题