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 pretty sure the release notes mention that string-backed enums are not currently supported. Have also seen posts on the dev forums about enums not working, period. Haven’t tried it myself, though.

@sfko I admit to not reading the release notes, but I tried Int backed first, so it shouldn't just be the prior. The latter sounds pretty plausible.

The forums you're referring to are these ones? https://forums.swift.org/

Swift Forums

Swift Forums

Swift Forums
Error saving @Model with enum | Apple Developer Forums