Reputation: 157
I'm new with Firebase in Swift and I see that there are more people in the same boat. My idea here is to retrieve the score of each player. Firebase db is like this:
Which is on the root reference (dbRef = FIRDatabase.database().reference()
)
My code is doing this:
dbRef.queryOrdered(byChild: "score").observeSingleEvent(of: .value) { (snap: FIRDataSnapshot) in
for child in snap.children{
print(child)
}
}
Which is generating these messages in terminal:
Snap (zfUNewjOCsQ5VCtSLFXSXLSFXtJ3) {
addedByUser = "[email protected]";
score = 100;
}
Snap (yfJqO65qCwTTlgzrcw1ovmPgZ6l2) {
addedByUser = "[email protected]";
score = 1000;
}
How to get on the score so the message printed in terminal be like:
100
1000
thanks in advance
Upvotes: 0
Views: 102
Reputation: 599946
You'd use childSnapshotForPath
to get to the score:
dbRef.queryOrdered(byChild: "score").observeSingleEvent(of: .value) { (snap: FIRDataSnapshot) in
for child in snap.children{
print((child as AnyObject).childSnapshot(forPath: "score").value)
}
}
Upvotes: 1