I'm trying to retrieve data from firebase database, but when I run the code it display nothing, though no errors shown
I got this piece of code from Firebase manual, by the way, I'm pretty sure that the path is correct
let ref = FIRDatabase.database().reference()
ref.child("users").child("user").child(username).observeSingleEvent(of: .value, with: { (snapshot) in
// Get user value
let value = snapshot.value as? NSDictionary
let score = value?["score"] as? String ?? ""
print(score)
// ...
}) { (error) in
print(error.localizedDescription)
}
JSON
{
"users" : {
"user" : {
"e1410kokeZS8xv81J1RzhN4V2852" : {
"email" : "aaaa@gmail.com",
"score" : 0,
"username" : "Afnan"
},
"jPx8XJ3Q9AazDM7qIOhz02PBfh22" : {
"email" : "aaaa@ggg.com",
"score" : 13,
"username" : "ghhh"
}
}
}
}