NSPredicate

A definition of logical conditions used to constrain a search either for a fetch or for in-memory filtering.

Overview

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 which is parsed by the class methods on NSPredicate. Examples of predicate format strings include:

  • Simple comparisons, such as grade == "7" or firstName like "Shaffiq"

  • Case and diacritic insensitive lookups, such as name contains[cd] "itroen"

  • Logical operations, such as (firstName like "Mark") OR (lastName like "Adderley")

  • 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 the predicate can be predefined before substituting concrete values at runtime.

posted @ 2017-08-29 19:30  zzfx  阅读(217)  评论(0编辑  收藏  举报