Reputation: 590
In a view controller, I have multiple observer codes. All of them working correctly except one. I'm sure child paths are correct. Observe function is correct. I tried in different a view controller and it worked correctly. Here is my firebase structure:
And here is my observer function.
func downloadUserData(){
if let currentUser = FIRAuth.auth()?.currentUser{
print("AZAT: download user data id \(currentUser.uid))")
DataService.ds.REF_USERS.child(currentUser.uid).observe( .value, with: {(snapshot) in
if let userDict = snapshot.value as? Dictionary<String,Any>{
print("AZAT: userdict is \(userDict)")
let user = User(userData: userDict)
self.users.insert(user, at: 0)
}
})
}
}
And I call this function in viewDidLoad()
. The REF_USERS
is correct, I'm pretty sure.
Thanks for your help.
Upvotes: 2
Views: 872
Reputation: 2718
func downloadUserData(){
if let currentUser = FIRAuth.auth()?.currentUser{
print("AZAT: download user data id \(currentUser.uid))")
DataService.ds.REF_USERS.child(currentUser.uid).observe( .value, with: {(snapshot) in
if let lastNameReceived = (snapshot.value as? NSDictionary)?["lastName"] as? String{
print("lastName value is \(lastNameReceived)")
}
if let userDict = snapshot.value as? Dictionary<String,Any>{
print("AZAT: userdict is \(userDict)")
let user = User(userData: userDict)
self.users.insert(user, at: 0)
}
})
}
}
Upvotes: 1