0

My data tree is organized like so:

  • users
    • user id generated by firebase
      • userHighScore: "100"
      • userName: "Sally"
      • userNation: "USA"
    • another user id generated by firebase
      • userHighScore: "92"
      • userName: "Jim"
      • userNation: "Canada" etc

Here's a screenshot: Screenshot of Firebase

I'd like to fetch the info of the users with the top 100 scores from Firebase and display the userName, userNation, and userHighScore in a TableView (starting with the highest score first).

I have a TableView set up on my TopScoreViewController.swift and have it connected as "@IBOutlet var topScoreTableView: UITableView!"

I've also control+dragged from the table up into the yellow button so that it's set as both dataSource and delegate.

In the table, there's 1 Prototype Cell, and I dragged in a label.

I've added a new file called TopScoreTableViewCell.swift and connected the label in the prototype cell as "@IBOutlet var userNameLabel: UILabel!"

So far so good (I think).

But from here, but nothing seems to be working. I've found lots of articles about different pieces of this but I haven't yet had success in putting it all together.

Any help would be appreciated!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Derence
  • 408
  • 5
  • 18
  • Without seeing code, there's not a whole lot we can do to see what you might be doing wrong. But I can tell you right now that since your scores are stored as strings rather than numbers, they will not sort in numeric order. – Doug Stevenson Feb 28 '19 at 00:44
  • Also see this question we just got: https://stackoverflow.com/questions/54916534/firebase-orderbychild-order-is-not-correct and the one I closed it against. – Frank van Puffelen Feb 28 '19 at 01:00
  • Thanks for the tip Doug! I will see if I can get those saved as Int rather than string. – Derence Feb 28 '19 at 16:54
  • Thanks Frank! I will take a look at those. – Derence Feb 28 '19 at 16:54
  • The code you need is almost in the documentation see [Work with lists](https://firebase.google.com/docs/database/ios/lists-of-data#filtering_data) and check out the code snippet there. Combine with `.queryOrdered(byChild:` and you have the answer. – Jay Feb 28 '19 at 19:45

0 Answers0