I'm trying #swift and #swiftdata for the first time, and need help with an error.

I get: SwiftData/BackingData.swift:201: Fatal error: expected attribute to be Codable

while inserting this model into a context

@Model
final class Item {
var name: String
var kind: Kind

enum Kind: String, Codable {
case function
case module
}

init(name: String, kind: Kind) { ... }
}

Removing kind from the model fixes it.

Is this even my bug? Or a SwiftData issue?

@GregMorenz Did you ever find a solution to this problem? I'm running into the same thing, with a model that has a custom structure as an attribute.

@natemartinsf I didn't. I concluded that enum's just weren't properly supported in SwiftData and moved on without them in the model struct.

Which was fine for the app I was prototyping, the enum I wanted was just describing a string in the data model anyways, so I can calculate it at runtime. It certainly seems like a pretty big oversight from apple though.

@GregMorenz Yeah, I hope they fix it. I found a similar workaround for enums (store the raw value and create the enum as needed)

Unfortunately I’m running into the same issue with including a custom struct in my model, which I haven’t found a workaround yet.

Severely limits the ability to do any sort of complex model unfortunately. I guess I’ll wait for beta 6!