A workaround is to store the Int value for MediaType in Media instead and use a computed property to switch between Int and MediaType
@Model class Media {
private var type: Int
var mediaType: MediaType {
get { MediaType(rawValue: type) }
set { type = newValue.rawValue } }
}
//...
}
Which would give a predicate where we use Int values in the filtering
static var predicate: (Predicate<Media>) {
let image = MediaType.image.value
let predicate = #Predicate<Media> { media in
media.type == image
}
return predicate
}
Two other observations, you don't need a id property for your model, the @Model macro makes the type conform to PeristentModel that extends Identifiable so you already have that id property
And secondly I would personally use an enum instead of a struct:
enum MediaType: Int, Codable, Equatable, Hashable {
case image = 0
case video
case audio
}