I am implementing new #Index
macro announced at WWDC24 for SwiftData. This is simplified code for my model
import SwiftUI
import SwiftData
enum MyType: Int, Codable {
case Type1
case Type2
case Type3
}
@Model
final class MyModel {
#Index<MyModel>([.type])
var type: MyType
var value: Int?
var createdAt: Date
init(
type: MyType,
value: Int?
) {
self.type = type
self.value = value
self.createdAt = .now
}
}
When I try to create ModelContainer
for above, following error is thrown. I tried adding Equatable
and CaseItterable
to the enum, but with no luck. Hence the question, is there a way where I can create index on the enum?
Can’t create an index element with composite property