0

How to create an Array in Firebase realtime database in iOS using swift

note : I want to be able to append new elements without getting array value first an add element locally then setting it to database .

3
  • Can you, please, elaborate more? Because "Firebase has no native support for arrays." So, what exactly that you want to do? Commented Sep 8, 2021 at 10:05
  • I want to store messages of a conversation Commented Sep 8, 2021 at 10:05
  • 1
    See firebase.google.com/docs/database/ios/… Commented Sep 8, 2021 at 14:11

2 Answers 2

2

use childByAutoId()

Database.database().reference().child("arrayKey").childByAutoId().setValue("Value") }
Sign up to request clarification or add additional context in comments.

Comments

1

This should be achieved easily:

let ref = storageRef.child("your_child")
let array = ["First", "Second", "Third", "Fourth"]
ref.setValue(array)

2 Comments

I have tried this but adding o an element requires an api call to get all elements and then add the element locally and then setting it back to database .
can you please show your code / what you achieved so far?

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.