SwiftData Expressions
In iOS 18, SwiftData can make use of Foundation’s new
#Expression
macro to make it easier to build more complex predicates. From the WWDC session:Expressions allow for reference values that do not produce true or false but instead allow for arbitrary types.
You can then evaluate the expression as part of more complex predicate.
[…]
If you expand the expression macro or check the Expression documentation you’ll see it’s creating PredicateExpressions which appear to support a wide range of methods. Unfortunately I can’t seem to get most of them to work either in predicates or expressions.
Previously:
- NSManagedObjectID and PersistentIdentifier
- SwiftData and Core Data at WWDC24
- Dynamic Swift Predicates in macOS 14 and iOS 17