Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 不符合可解码/可编码协议_Swift_Swift4 - Fatal编程技术网

Swift 不符合可解码/可编码协议

Swift 不符合可解码/可编码协议,swift,swift4,Swift,Swift4,我正在使用以下结构: 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 f

我正在使用以下结构:

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)
    }

}
将weightOld更改为weightNew后,出现两个错误: -类型“Item”不符合协议“Decodable” -类型“Item”不符合协议“Codable”


如果我省略了“var weightNew:[Weight]”,它会起作用。不知道发生了什么以及如何解决它。。。谢谢你的帮助

一切都需要可编码。到目前为止,您的
Weight
结构是不可编码的。将
Weight
更新为可编码,然后
Item
将可编码。

struct Weight:Codable{…}
struct Weight {
    var day:Int
    var weight:Double
    var type:Bool
}