0

I got node in the firebase named "XXXXX". I want to add tokenids to this node.

But in iOS I am having problem updating tokensids.

Do we got functions in iOS for appending data to iOS Firebase?

or we have to first get the token from firebase , append our token and save the token array back to node ?

Any suggestion guys ?

2
  • To accept answer on stack overflow you need to tap green jackdaw btw:) Commented May 16, 2017 at 9:34
  • Accept one of the answers, please, to let other people know, that it helped, if it helped ofc Commented Jun 1, 2017 at 9:13

3 Answers 3

1

No, you cannot append data to an array in Firebase using any Firebase query.

But, there is a way by using dictionary as arrayObjectToAdd: true,

self.ref.child("ArrayMainNode").setValue(["arrayObjectToAdd": "true"])

To remove an array object, you can directly use

self.ref.child("ArrayMainNode").child("arrayObjectToAdd").removeValue()
Sign up to request clarification or add additional context in comments.

4 Comments

"No, you cannot append data to an array in Firebase using any Firebase query." are you sure in it?
you can store an array , replace an entire array but not append an object to array in Firebase. I have tried and this is the best solution, one which even Firebase supports.
github.com/Pulichev/RideWorldIOs/blob/VladPulichev/RideWorld/… - 57 line. Function. Working. "/posts/" is array. I'm not trying to be rude btw:)
But we both are saying the same thing. We need to add the object to the array as { object : true }. There isn't any Firebase method to append object to Array.
1

You can do it this way:

let ref = FIRDatabase.database().reference(withPath: "somePath/array").child(newArrayObjectKey)
ref.setValue("true") // or whatever

Hope it helps

Comments

1

You can do it by this way:

let refInsert = Database.database().reference()

self.refInsert.updateChildValues(["Your node": "\(new token)"])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.