wasif
wasif

Reputation: 327

Update a particular subchild in firebase realtime database swift 4

enter image description here 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

Answers (2)

Dris
Dris

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

Abdulmoiz Ahmer
Abdulmoiz Ahmer

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

Related Questions