NSPredicate
A definition of logical conditions for constraining a search for a fetch or for in-memory filtering.
Declaration
class NSPredicateOverview
Predicates represent logical conditions, which you can use to filter collections of objects. Although it’s common to create predicates directly from instances of NSComparisonPredicate, NSCompoundPredicate, and NSExpression, you often create predicates from a format string that the class methods parse on NSPredicate. Examples of predicate format strings include:
Simple comparisons, such as
grade == "7"orfirstName like "Juan"Case- and diacritic-insensitive lookups, such as
name contains[cd] "stein"Logical operations, such as
(firstName like "Mei") OR (lastName like "Chen")Temporal range constraints, such as
date between {$YESTERDAY, $TOMORROW}Relational conditions, such as
group.name like "work*"Aggregate operations, such as
@sum.items.price < 1000
For a complete syntax reference, refer to the Predicate Programming Guide.
You can also create predicates that include variables using the evaluate(with:substitutionVariables:) method so that you can predefine the predicate before substituting concrete values at runtime.
Topics
Creating a Predicate
init(format:argumentArray:)init(format:arguments:)init(format:_:)init(_:)withSubstitutionVariables(_:)init(value:)init(block:)init(fromMetadataQueryString:)