I want to save a custom enum to my SwiftData model. I can get it to work that it shows and even updates the value in the UI. Though, the change of the enum var/entity isn’t persisted when relaunching the app!
Any advice what to watch out for when using custom enums?
My Model
enum Type: Int, Codable {
case foo = 0
case bar = 1
}
@Model
final public class Item {
var type: Type
}
UI Code
struct DetailView: View {
@Bindable var item: Item
// MARK: -
var body: some View {
Picker("Type", selection: $item.type) {
Text("Foo").tag(Type.foo)
Text("Bar").tag(Type.bar)
}
.pickerStyle(.segmented)
}
}