Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.foundation |
Availability | Available in Mac OS X v10.4 and later. |
Companion guide |
The NSPredicate class is used to define logical conditions used to constrain a search either for a fetch or for in-memory filtering.
You use predicates to represent logical conditions, used for describing objects in persistent stores and in-memory filtering of objects. You often create predicates from a format string which is parsed by the class methods on NSPredicate; examples include:
Simple comparisons, such as grade == "7"
or firstName like "Shaffiq"
Case/diacritic insensitive lookups, such as name contains[cd] "itroen"
Logical operations, such as (firstName like "Mark") OR (lastName like"Adderley")
You can create predicates for relationships, such as:
group.name matches "work*"
ALL children.age > 12
ANY children.age > 12
You can also create predicates for operations, such as @sum.items.price < 1000
.
In general, the order for like
and matches
predicates is propertyName OPERATOR pattern
.
It is also common to create predicates directly—this is more efficient, more (type-)safe, and it avoids localization issues.
You can also create predicates that include variables, so that they can be pre-defined (in a tool) before substituting concrete values at runtime. For predicates that use variables, evaluation is a two step process (see predicateWithSubstitutionVariables
and evaluateWithObject
).
public NSPredicate
()
Creates an empty NSPredicate object.
Returns a new predicate by substituting the values in arguments into predicateFormat in the order they appear, and parsing the result.
public static NSPredicate predicateWithFormat
(String predicateFormat, NSArray arguments)
public static NSPredicate predicateWithValue
(boolean value)
Returns a predicate that always evaluates to value.
Returns true
if object matches the conditions specified by the receiver; otherwise false
public boolean evaluateWithObject
(Object object)
.
public String predicateFormat
()
Returns the receiver’s format string.
Returns a copy of the receiver with the receiver’s variables substituted by values specified in the substitution variables dictionary.
public NSPredicate predicateWithSubstitutionVariables
(NSDictionary variables)
The substitution variables dictionary is specified by variables which must contain key-value pairs for all variables in the predicate.
The receiver itself is not modified by this method, so you can reuse it for any number of substitutions.
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)