Firebase - how to get the key value in observeEventType = Value

后端 未结 3 834
礼貌的吻别
礼貌的吻别 2020-12-06 08:39

This is a follow up question to Firebase - proper way to structure the DB

I have the following DB structure:

\"artists\" : {
  \"-KKMkpA22PeoHtBAPyKm         


        
3条回答
  •  长情又很酷
    2020-12-06 09:35

    Here's a solution.

    let ref = self.myRootRef.childByAppendingPath("artists")
    
    ref.queryOrderedByChild("name").queryEqualToValue("Skillet")
         .observeEventType(.Value, withBlock: { snapshot in
    
         if ( snapshot.value is NSNull ) {
              print("Skillet was not found")
         } else {
              for child in snapshot.children {   //in case there are several skillets
                   let key = child.key as String
                   print(key)
              }
         }
    })
    

提交回复
热议问题