2016-09-23 62 views

回答

2

夫特2

FIRDatabase.database().reference().child("events").queryOrderedByChild("id").queryEqualToValue(4).observeSingleEventOfType(.Value, withBlock: {(Snap) in 
    if let snapDict = Snap.value as? [String:AnyObject]{ 
     for each in snapDict{ 
      print(each.0) // Will print out your node ID = 1 
      print(each.1) //Will print out your Dictionary inside that node. 
      } 

     } 

    }) 

夫特3

FIRDatabase.database().reference().child("events").queryOrdered(byChild: "id").queryEqual(toValue: 4).observeSingleEvent(of: .value, with: {(Snap) in 
     if let snapDict = Snap.value as? [String:AnyObject]{ 
      for each in snapDict{ 
       print(each.0) // Will print out your node ID = 1 
       print(each.1) //Will print out your Dictionary inside that node. 
      } 

     } 

    }) 
+0

接受此爲答案,如果它解決了您的問題:)快樂編碼 – Dravidian

+0

什麼是安靜的代碼。它真的幫助了我。 非常感謝 – Aleksandar

1

可能會解決你的問題

[self.dbRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) { 
    if (![snapshot.value isKindOfClass:[NSNull class]]) { 
     NSArray *arrResponse = (NSArray *)snapshot.value; 

     NSPredicate *pred = [NSPredicate predicateWithFormat:@"id = %@", serchID]; 
     NSArray *arrSearchedVal = [arrResponse filteredArrayUsingPredicate:pred]; 
    } 
}]; 

NB: DBREF是你FIRDatabaseReference,這返回整個數據JSON。然後用您的搜索ID使用NSPredicate,您將得到您的結果。

enter image description here

enter image description here

編碼愉快..

+0

WC ...很高興爲您提供幫助.. –