0

so I try to sort data from with most likes to the least. How do I do that if don't have an object name? because currently I only have the ID of the object?

here's my Firebase json:

["-KfSODzRPjy46ayCFRBH": {
      "_createdAt" = 1489773065234;
      "_updatedAt" = 1489773065234;
      content =     (
                     "<null>",
                     Tittle,
                     "why not there is the nnnd ksksks lalalalalkdkdkdkdk kadsjfakl;",
                     whhhhhhalalallala
                    );
      imageTitle = 1489773064177;
      like = 2;
      title = "Third Post";
}, 

["-KfSODzRPjy46ayCFRBH": {
      "_createdAt" = 1489773065234;
      "_updatedAt" = 1489773065234;
      content =     (
                     "<null>",
                     Tittle,
                     "why not there is the nnnd ksksks lalalalalkdkdkdkdk kadsjfakl;",
                     whhhhhhalalallala
                    );
      imageTitle = 1489773064177;
      like = 3;
      title = "Third Post";
}, 

this is how I read:

        let handleref = databaseRef.child("v1/postmodel").observe(.value, with: { (snapshot) in
        let postDict = snapshot.value as! [String : AnyObject]
        print(postDict)
    })
Buka Cakrawala
  • 189
  • 1
  • 8
  • Sorting in Firebase http://stackoverflow.com/questions/42249524/sorting-items-position-using-firebaserecycleradapter and http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase?noredirect=1&lq=1 – Khaledonia Mar 17 '17 at 18:09
  • 1
    See [order/filter data](https://firebase.google.com/docs/database/ios/lists-of-data#filtering_data) and then loop over the results with `snapshot.children` as [documented here](https://firebase.google.com/docs/database/ios/lists-of-data#listen_for_value_events) (since converting the snapshot to a dictionary will otherwise lost the order). – Frank van Puffelen Mar 17 '17 at 18:20

0 Answers0