I had a similar problem with Beta 6, and still having it after upgrading to Beta 8. It seems that using a Boolean test against a stored enum value always fails within a #Predicate definition. I've tried to make it work both with an @Query macro and a 'let myPredicate = #Predicate { $0.someValue == myStoredEnum.someValue && ...}' statement. One other strange thing is that when I inspect one particular enum definition, the raw value shows as being of type String, when the enum is clearly designated 'enum: Int, Codable {...}
Post
Replies
Boosts
Views
Activity
I did a little more digging and came across this post "SwiftData. Predicate. Issue accessing self (Entity) inside a Predicate". This gave me the insight into a solution that worked for me. My use case is that I'm using a Picker to select from a stored enum value, and then using that value to build a search predicate. Since stored enum values have an implicit 'self' prepended to their value references (ie. myStoredEnum.value1 could be fully written out as self.myStoredEnum.value1), I was unknowingly throwing sand in the search predicate gears with the implicit 'self'. My workaround is to use an intermediate variable to hold the enum value and then build the search predicate using the intermediate variable instead of directly with the enum value. Yes it's cludgy, but it does seem to work. Hopefully Apple will figure it out so that references to 'self' don't fail in search predicates and we can delete the workaround.
For background, I'm running Xcode 15.0 on macOS Ventura 13.5.2.