我正在使用以下结构体:
struct Item : Codable {
var category:String
var birthDate:Date
var switch:Bool
var weightNew: [Weight]
var weightOld: Array<Double>
var createdAt:Date
var itemIdentifier:UUID
var completed:Bool
func saveItem() {
DataManager.save(self, with: itemIdentifier.uuidString)
}
func deleteItem() { DataManager.delete(itemIdentifier.uuidString)
}
mutating func markAsCompleted() {
self.completed = true
DataManager.save(self, with: itemIdentifier.uuidString)
}
}
而对于重量:
struct Weight {
var day:Int
var weight:Double
var type:Bool
}
将weightOld更改为weightNew后,我收到了两个错误: - 类型“Item”不符合协议“Decodable” - 类型“Item”不符合协议“Codable”
如果我省略'var weightNew:[Weight]',它可以工作。不知道发生了什么以及如何解决...需要帮助。