My Firestore document structure, i created it via Android:
--- Document
----- testA (object)
----- testB (array)
------- 0: Device item 1
------- 1: Device item 2
I have following struct:
import Foundation
public struct Device: Codable {
var manufacturer: String?
var model: String?
var osVersion: String?
enum CodingKeys: String, CodingKey {
case manufacturer
case model
case osVersion
}
}
My device object
let currentDevice = Device(manufacturer: "a", model: "b", osVersion: "c")
Test A: Update Device to Document.
I tried below code:
db.collection("testCollection").document("testDoc").updateData([testA: currentDevice])
...
Test B: Add Device to testB array.
db.collection("testCollection").document("testDoc")
.updateData([testA: FieldValue.arrayUnion([currentDevice])])
It all cause below error: Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason: 'Unsupported type: __SwiftValue'
I also checked official document but it does not show anyway to update struct object to Firestore. What can i do? Thanks.