我正在使用以下结构:
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)
}
}
Run Code Online (Sandbox Code Playgroud)
而对于重量:
struct Weight {
var day:Int
var weight:Double
var type:Bool
}
Run Code Online (Sandbox Code Playgroud)
将weightOld改为weightNew后,我得到两个错误: - Type'Item'不符合协议'Decodable' - Type'Item'不符合协议'Codable'
如果我遗漏'var weightNew:[Weight]'就可以了.不知道发生了什么以及如何解决它...帮助表示赞赏.
| 归档时间: |
|
| 查看次数: |
7460 次 |
| 最近记录: |