19

I'm using the following struct:

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

}

And for weight:

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

After changing weightOld to weightNew I get two errors: - Type 'Item' does not conform to protocol 'Decodable' - Type 'Item' does not conform to protocol 'Codable'

If I leave out 'var weightNew: [Weight]' it works. Don't know what is happening and how to solve it... Help is appreciated.

arakweker
  • 1,535
  • 4
  • 18
  • 40

1 Answers1

29

Everything needs to be Codable. So far your Weight struct is not Codable. Update Weight to be Codable as well and then Item will be Codable.

rmaddy
  • 314,917
  • 42
  • 532
  • 579