swift transfer current firebase auth user UID to firestore document site:stackoverflow.com code example
Example: swift firebase read key in autoKey
struct User{
var id:String
var username:String?
var occupation:String?
var age:Int?
var bio:String?
var email:String?
}
let query = self.ref.child("Users").queryOrdered(byChild: "email")
query.observeSingleEvent(of: .value) {
(snapshot) in
for child in snapshot.children.allObjects as! [DataSnapshot] {
let id = child.key
let value = child.value as? NSDictionary
let username = value?["Username"] as? String
let occupation = value?["Occupation"] as? String
let age = value?["Age"] as? Int
let bio = value?["Bio"] as? String
let email = value?["email"] as? String
let user = User(id: id, username: username, occupation: occupation, age: age, bio: bio, email: email)
self.usersArray.append(user)
}
completion("Users list fetched")
}