0

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 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I want store the values like this Price: 0: item1: value item2: value 1: item1: value item2: value
@AbdulelahAlharabi Edit the answer, please check)
0

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

1 Comment

Cannot convert value of type '[[String : String]]' to expected argument type '[AnyHashable : Any]'

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.