Reputation: 1625
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.
Upvotes: 19
Views: 13528
Reputation: 318804
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.
Upvotes: 29