I have this function written in Swift that fetch the leaderboard and then shows it to the user :
@IBAction func onShowLeaderboardTapped(_ sender: Any) {
Change the structure
scores
-YUijia099sma
name: "Ben"
score: 9
-Yij9a9jsffffd
name: "Dimitar"
score: 7
then
@IBAction func onShowLeaderboardTapped(_ sender: Any) {
let leaderboardDB = FIRDatabase.database().reference().child("scores")
.queryOrdered(byChild: "score")
.queryLimited(toLast: 5)
leaderboardDB.observeSingleEvent(of: .value, with: { (snapshot) in
print("leaderboard snapshot:" ,snapshot)
}, withCancel: nil)
}
*typing on my iPad so it's not tested and the syntax may not be perfect