How to make SwiftData class Codable

Consider the Categories class below.

Without the @Model line, Xcode has no problems. As soon as the @Model line is added, Xcode protests that the class does not conform to Decodable or Encodable.

Apparently the @Model macro expanded macro prevents the implied boilerplate that the systems adds when the Codable protocol is added to the class.

I've filed feedback (FB12444837) for this. Does anyone have suggestions that will let me avoid the boilerplate? This is the simplest class in my schema, I've got 12 other classes with many more variables.

@Model
class Categories: Identifiable, Codable {
    
    // MARK: Identifiable
    var id: UUID { return uuidKey }
    
     // MARK: - Properties
    @Attribute(.unique) var uuidKey: UUID = UUID()
    var dateCreated: Date = Date()
    var dateModified: Date = Date()
    var dateRealm: Date? = nil
    var uuidUser: UUID = UUID()
    var uuidFamily: UUID = UUID()
    var myName: String = ""
}

I'm also stuck here. In my case it seems caused by the appearance of the model in the predicate of a fetch descriptor.

I have the same issue! Any news?

Check this out for the explanation and solution: https://www.donnywals.com/making-your-swiftdata-models-codable/

I made simple Swift Macro here is article how to use it https://kment-robin.medium.com/codable-and-swiftdata-179418b2c460

You can use MetaCodable macro library I created.

How to make SwiftData class Codable
 
 
Q