Matt Butler Matt Butler - 2 months ago 15
Swift Question

Update existing data in Firebase (Swift)

Firebase Data Structure:

users
- 90384m590v834dfgok34
•userName: "Matt"
•values: ["test1", "test2"]


I am wanting to update the values inside of these firebase entries without replacing the whole thing. I know the update() function is what I need to do, but from the example I tried it is not working.

Also, how would I append a new item to the values array through the update() function?

Answer

Create a reference for the user whose values you'd like to update and use updateChildValues.

let ref = FIRDatabase.database().reference().child("users/90384m590v834dfgok34")

ref.updateChildValues([
    "values": [
        "test3",
        "test4"
    ]
])