0
votes

I have an array with struct type

struct name { 
    item1: String
    item2: String
}

How can I upload array with this struct value to Firebase Database

Note: When I try to post an array with this struct value Xcode always give me this error

Terminating app due to uncaught exception 'InvalidFirebaseData', reason: '(setValue:) Cannot store object of type _SwiftValue at Price.0. Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray.'

I want store the values like this

Price:
    0:
       item1: value
       item2: value
    1:
       item1: value
       item2: value
2

2 Answers

1
votes

Firebase can't store this type. You can download it this way

Database.database().reference().child("Price").child("NUMBER").setValue(["item1" : ITEM1_VALUE, "item2" : ITEM2_VALUE])

Number is your count, you can implement it each time

0
votes

Try this:

let price = [["item1":value,"item2":value],["item1":value,"item2":value]]
Database.database().reference().child("Price").updateChildValues(price)

Reference: https://firebase.google.com/docs/database/ios/read-and-write