I test with a simple class and it can compile:
@Model
final class Book: Encodable {
var name: String
enum CodingKeys: CodingKey {
case name
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
}
}
Then I try with the Trip class from sample and it cause an error:
@Model final class Trip: Encodable {
:
enum CodingKeys: CodingKey {
case name, destination, endDate, startDate, bucketList
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
try container.encode(destination, forKey: .destination)
try container.encode(endDate, forKey: .endDate)
try container.encode(startDate, forKey: .startDate)
try container.encode(bucketList as! Set<BucketListItem>, forKey: .bucketList)
}
And I got the error Ambiguous use of 'setValue(for:to:)'
I tried make BucketListItem and LivingAccommodation Encodable and still have error.