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 See if you can debug it using ChatGPT! It may tell you the issue, it does really well with identification of issues and explaining them!

@AndrewMettier SwiftData and the error message are both new (Google still returns no results found for "Fatal error: expected attribute to be Codable"), ChatGPT is... unlikely... to have the right context to help since it's training data is all from before any of this existed.

On a basic attempt it returns something confident sounding, but that does not fix the issue... and doesn't really make sense if you stop to think about it: https://chat.openai.com/share/a48b19e9-122f-406e-8218-daada705594f

ChatGPT

A conversational AI system that listens, learns, and challenges