So far, every time a user is adding data, the realtime database is being updated. That's it.

driven
    - users
        - uid
            - currentKm
            - ...

Now I want to save more data adding a further branch with a further ID (addID is a value inside of the class) as a name:

driven
    - users
        - uid
            - currentKm
            - ...
            - addID
                - driven
                - ...

How am I able to do so?


That's how my code looks so far:

 func updateData() {
        guard let uid = Auth.auth().currentUser?.uid else { return }
        let databaseRef = Database.database().reference().child("users/\(uid)")

        databaseRef.updateChildValues([
                "currentKm": currentKm,
                ...
            ])
    }

1 Answers

0
Sh_Khan On Best Solutions

updateChildValues accepts [String:Any]

let inner:[String:Any] = ["key":"value"]
let str:[String:Any] = ["currentKm": currentKm,
                       "addID":inner]

databaseRef.updateChildValues(str)