1

If my database structure is like this: enter image description here

and I have this:

    ref = Database.database().reference().child(passUserID)

    ref?.child("wins").updateChildValues("wins": numerator)

where numerator = (games played beforehand) + (games played after logging in), for the second statement it is giving me an error in the expression that I don't know how to fix.

Also if I try to do this instead:

ref?.child("wins").setValue(numerator)

it messes up my data bad and gives a bad instruction error.

yuin265
  • 93
  • 2
  • 9

2 Answers2

1

The updateChildValues method takes a Dictionary. So you just need to call the method with a dictionary containing the key-value pairs you want to update, i.e.

ref = Database.database().reference().child(passUserID)

ref?.updateChildValues(["wins": numerator])

For more on how to read/write data to firebase realtime database, refer to: https://firebase.google.com/docs/database/ios/read-and-write

PGDev
  • 23,751
  • 6
  • 34
  • 88
0

If you use .setValue triggers only in the beginning. Instead of .setValue use updateChildValues(.values/.childAdded/.childRemoved etc..) to update the values inside your tree. It will be executed whenever changes occurs to your node.

How to update particular value of child in Firebase DB

Developer Omari
  • 434
  • 5
  • 14