Reputation: 27
I have a Firebase Real Time Database that looks like this:
I am trying to read the value
attribute of Balance
, but I am not getting any response when I run this code in Swift:
var userID = Auth.auth().currentUser?.uid
var ref = Database.database().reference()
func observeDB() {
ref.child(userID!).child("Balance").observe(.childAdded, with: { snapshot in
let userDict = snapshot.value as! [String: Any]
print(userDict["value"] as! String)
})
}
Is there another way that I can solve this problem? Thanks!
Upvotes: 0
Views: 50
Reputation: 598847
This seems simpler to me:
ref.child(userID!).child("Balance/value").observe(.value, with: { snapshot in
print(snapshot.value)
})
Differences with your code:
value
child of Balance
..value
event.Both seems more direct translations of what you're trying to accomplish.
Upvotes: 1