Why? I've seen some discussion threads where this error message pops up when an optional is involved in a KeyPath, but that's not the case here. And there's not multiple components. This is essentially the simplest possible Predicate, lifted straight out of the example in the documentation, and it crashes at runtime. I'm a little mystified.
Details
Swift Language Version: 6
Xcode Version: 16.2
Deployment Target: macOS 15.2
This is a brand-new Xcode Project. I added the Foo class and then one single line in -applicationDidFinishLaunching() to construct the Predicate.
I'm not sure if this is technically a "Swift Language" issue or a Foundation issue, but I've asked the question in more general places (SO) and gotten nothing. Swift Predicates are pretty new, the documentation is very sparse, and I'm hoping the Swift Forums have more expertise.
You're correct: a struct worked just fine. So I started playing around with inheriting from NSObject, confirming to @Model (because I have other apps that use Predicates on SwiftData classes and those work just fine) and then finally, for no reason at all, I removed the final keyword. When I removed that, it worked. No other changes needed.
That has to be a bug, right? At the very least, if Predicates can't work with final classes, the error message being displayed (keypaths with multiple components) is entirely misleading.