Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...