Ok a bit more info, so it seems that it's more related to the fact that SwiftData doesn't like filtering or sorting on optional values... Below is an example of me filtering based on a non optional string and the fetch request works
let fetch = FetchDescriptor<Item>(predicate: #Predicate { $0.title == "G" })
let results = try? modelContext.fetch(fetch)
print("Found \(results?.count) items") <--- This returns results that match the query
When trying to filter and sort on optional properties like an enum or my property category this is where the issue arises... It seems to crash when trying to access the rawValue and also you get no results when you try to filter based on the case. Below is an example of be executing a query on an optional enum.
let high: Priority = Priority.high
let fetch = FetchDescriptor<Item>(predicate: #Predicate { $0.priority == high })
let results = try? modelContext.fetch(fetch)
print("Found \(results?.count) items") <--- Returns nothing & accessing the raw value crashes...
I hope someone on the Apple team sees this since it seems SwiftData and optionals just don't play nicely...
This is on Xcode 15 RC