I am trying to create a user info database and observe them by using firebase for every single user. the creation part went good I think but when I call the observeSingleEvent
and print the snapshot value, it says that the snapshot is null. Can you guys help me with that?
here is what my firebase database console shows;
>sinav-be280
>>member
>>>'SffbOC1UoYcmfBNCrjn2aOhFM4F2'
>>>>mail: "1@1.com"
>>>>name: "1"
>>>>password: "123123"
>>>>phone: "1"
here is my code
func createUserIfno() {
let userInfoDB = ref.child("member")
let userDictionary = [
"name": self.nameTextView.text!,
"phone": self.phoneNumberTextField.text!,
"mail": Auth.auth().currentUser ? .email!,
"password" : self.passwordTextField.text!,
]
userInfoDB.child(userID!).setValue(userDictionary) {
(error, reference) in
if error != nil {
print(error!)
} else {
print("info saved")
}
}
}
func printUserInfo() {
let userInfoDB = ref.child("member").child(userID!)
userInfoDB.keepSynced(true)
userInfoDB.observeSingleEvent( of: .value, with: {
(snapshot) in
if !snapshot.exists() {
print("snapshot does exist")
print(snapshot)
return
}
})
}
it says ;
snapshot does exist
Snap (1jMpyCCbt0crfUdINnlSupRdcqk1) <null>
and I don't even know what is the 1jMpyCCbt0crfUdINnlSupRdcqk1
id.
Actually i played with the code a little and solved the problem.
In my app i wrote the code for creating a user and creating a database separately so in firebase, somehow first user id goes to second user's info list and second goes the third. So i called my createUserInfo func within the createUser func and problem solved.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.