Reputation: 327
The screenshot above is of the database i created. I successfully am able to upload and retreive data through code but i dont know how to update a subchild. For instance if i want to update the subchild user_name how can i acheive this in swift any snippet would be appreciated.
Upvotes: 1
Views: 793
Reputation: 844
It's simple, you need just call setValue on the child like this:
ref.observeSingleEvent(of: .value, with: { (snapshot) in
self.ref.child("USERS").child(email).child("user_name").setValue("new User Name")
})
Upvotes: 2
Reputation: 2351
ref.child("USERS").child(email).child("user_name").setValue("new user name"){
(error:Error?, ref:DatabaseReference) in
if let error = error {
//error
} else {
//do stuff
}
}
}
Upvotes: 4