Reputation: 425
i am spend lot of time i can not figure out . why why it is not parse .
func fetchUser(_ uid: String) {
FIRDatabase.database().reference().child("users").child("g373gSvDcFhXNAGh5V6vg7sU5C02").observe(.childAdded, with: {
(snapshot) in
//TODO...
print(snapshot) //Snap (email) [email protected]
let user = snapshot.value as ? [String: Any]
print(user) //nil
if let _nameLabel = self.nameLabel,
let name = user ? ["name"] as ? String {
_nameLabel.text = "{-} \(name)"
}
}, withCancel: nil)
}
Upvotes: 0
Views: 284
Reputation: 7324
Problem:
You use the event type .childAdded
for observing
case childAdded is fired when a new child node is added to a location
Solution:
You should change the event type from .childAdded
to .value
like this:
FIRDatabase.database().reference().child("users").child("g373gSvDcFhXNAGh5V6vg7sU5C02").observe(.value, with: { (snapshot) in
// other code
})
Upvotes: 2