我想将对象数组作为字段插入 Firestore 文档中。我拥有的是:
struct Race {
...other properties
results: [RunnerResult]
}
struct RunnerResult { ... }
func saveRace(race: Race) {
database.collection("Races").document(race.id).setData(
...other properties
results: race.results,
)
}
但是每当它尝试保存并出现错误
results: race.results
时,它就会在线Unsupported type: __SwiftValue
上崩溃。是否可以将对象数组直接保存到 Firestore 中,还是需要操作数据?
您的意思可能是这样的吗(这是一个加密示例(始终隐藏您的密钥。这些只是编造的......))?
let db = Firestore.firestore()
@IBAction func SaveDataSet1(_ sender: UIButton) {
Task { @MainActor in
let key256 = "09754896534186486564891846888562"
let iv = "mznfojdlaougnhu"
let aes256 = AES(key: key256, iv: iv)
let encryptedFirstName = aes256?.encrypt(string: textfieldforFIRSTNAME.text!)
db.collection("Races").addDocument(data: [
"First name": encryptedFirstName
]) { (error) in
if error != nil {
print("There was an issue saving the data", error!)
} else {
print("Success!")
}
}
}