Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

swift - Firebase query ordering not working properly

Basically I have played with Firebase for the past week, and I recently stumbled upon the 'queryOrderedByChild()' that as far as I know - allows you to sort data in firebase. However, I seem to not get the proper results. My Firebase data looks like this:

{
  "names" : {
    "-KHVUwXdVPHmrO_O5kil" : {
      "id" : "0",
      "name" : "Jeff"
    },
    "-KHVV7lCeac0cZNMi9fq" : {
      "id" : "3",
      "name" : "Stig"
    },
    "-KHVVCjXgl0XxasVOHF1" : {
      "id" : "13",
      "name" : "Ali"
    },
    "-KHVVJtyUO-yJZiompJO" : {
      "id" : "7",
      "name" : "Hannah"
    },
    "-KHVVR8tMSO1Oh7R8tR1" : {
      "id" : "2",
      "name" : "Amanda"
    }
  }
}

, and my code looks like this:

ref.childByAppendingPath("names")
   .queryOrderedByChild("id")
   .observeEventType(.ChildAdded) { (snapshot:FDataSnapshot!) in
       if let myID = snapshot.value["id"] as? String {
           print(myID)
       }

The output is still in a random order, displaying: 0, 2,7,1,8,4 - Isn't this supposed to be numeric? What am I doing wrong? How can I sort it so it get's numeric either ascending or descending?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...