ios - Firebase Retrieving Data in Swift -
i'm trying retrieve specific data logged in user. data in database looks this:
for example, want grab full_name , save in variable username. below i'm using grab data
ref.queryorderedbychild("full_name").queryequaltovalue("useridentifier").observesingleeventoftype(.childadded, withblock: { snapshot in print(snapshot.value) // let username = snapshot.value["full_name"] as! string })
unfortunately, console prints.
i appreciate :) thank you!
it gives warning message indexon
because doing query.
you should define keys indexing on via .indexon rule in security , firebase rules. while allowed create these queries ad-hoc on client, see improved performance when using .indexon
as know name looking can directly go node, without query.
let ref:firdatabasereference! // ref ie. root.child("users").child("stephenwarren001@yahoo.com") // need fetch once use single event ref.observesingleeventoftype(.value, withblock: { snapshot in if !snapshot.exists() { return } //print(snapshot) if let username = snapshot.value["full_name"] as? string { print(username) } if let email = snapshot.value["email"] as? string { print(email) } // can use // snapshot.childsnapshotforpath("full_name").value as! string })
Comments
Post a Comment