API 0.9.5
CPPredicate Class Reference

The CPPredicate class is used to define logical conditions used to constrain a search either for a fetch or for in-memory filtering. More...

#import <CPPredicate.h>

Inheritance diagram for CPPredicate:

List of all members.

Instance Methods

(CPString- description
(BOOL) - evaluateWithObject:
(BOOL) - evaluateWithObject:substitutionVariables:
(CPString- predicateFormat
(CPPredicate- predicateWithSubstitutionVariables:

Class Methods

(CPPredicate+ predicateWithFormat:
(CPPredicate+ predicateWithFormat:argumentArray:
(CPPredicate+ predicateWithFormat:arguments:
(CPPredicate+ predicateWithValue:

Detailed Description

The CPPredicate 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. Although it is common to create predicates directly from instances of CPComparisonPredicate, CPCompoundPredicate, and CPExpression, you often create predicates from a format string which is parsed by the class methods on CPPredicate. Examples of predicate format strings 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")
  • “Between” predicates such as date between {$YESTERDAY, $TOMORROW}.

You can create predicates for relationships, such as:

  • group.name like "work*"
  • ALL children.age > 12
  • ANY children.age > 12

You can create predicates for operations, such as @sum.items.price < 1000.

You can also create predicates that include variables, so that the predicate can be pre-defined before substituting concrete values at runtime with the evaluateWithObject:substitutionVariables: method.

Definition at line 2 of file CPPredicate.h.


Method Documentation

- (CPString) description

Definition at line 153 of file CPPredicate.j.

- (BOOL) evaluateWithObject: (id)  object

Returns a Boolean value that indicates whether a given object matches the conditions specified by the receiver.

Parameters:
objectThe object against which to evaluate the receiver.
Returns:
YES if object matches the conditions specified by the receiver, otherwise NO.

Reimplemented in CPComparisonPredicate, and CPCompoundPredicate.

Definition at line 127 of file CPPredicate.j.

- (BOOL) evaluateWithObject: (id)  object
substitutionVariables: (CPDictionary variables 

Returns a Boolean value that indicates whether a given object matches the conditions specified by the receiver after substituting in the values in a given variables dictionary.

Parameters:
objectThe object against which to evaluate the receiver.
variablesThe substitution variables dictionary. The dictionary must contain key-value pairs for all variables in the receiver.
Returns:
YES if object matches the conditions specified by the receiver after substituting in the values in variables for any replacement tokens, otherwise NO.

Reimplemented in CPComparisonPredicate, and CPCompoundPredicate.

Definition at line 138 of file CPPredicate.j.

- (CPString) predicateFormat

Returns the receiver’s format string.

Returns:
The receiver’s format string.

Reimplemented in CPComparisonPredicate, CPCompoundPredicate, and CPPredicate_BOOL.

Definition at line 148 of file CPPredicate.j.

+ (CPPredicate) predicateWithFormat: (CPString format
,   ... 

Creates and returns a new predicate formed by creating a new string with a given format and parsing the result.

Parameters:
formatThe format string for the new predicate.
A comma-separated list of arguments to substitute into format.
Returns:
A new predicate formed by creating a new string with format and parsing the result.

Definition at line 63 of file CPPredicate.j.

+ (CPPredicate) predicateWithFormat: (CPString format
argumentArray: (CPArray args 

Creates and returns a new predicate by substituting the values in a given array into a format string and parsing the result.

Parameters:
formatThe format string for the new predicate.
argumentsThe arguments to substitute into predicateFormat. Values are substituted into predicateFormat in the order they appear in the array.
Returns:
A new predicate by substituting the values in arguments into predicateFormat, and parsing the result.

Definition at line 78 of file CPPredicate.j.

+ (CPPredicate) predicateWithFormat: (CPString format
arguments: (va_list)  argList 

Creates and returns a new predicate by substituting the values in an argument list into a format string and parsing the result.

Parameters:
formatThe format string for the new predicate.
argListThe arguments to substitute into predicateFormat. Values are substituted into predicateFormat in the order they appear in the argument list.
Returns:
A new predicate by substituting the values in argList into predicateFormat and parsing the result.

Definition at line 95 of file CPPredicate.j.

- (CPPredicate) predicateWithSubstitutionVariables: (CPDictionary variables

Returns a copy of the receiver with the receiver’s variables substituted by values specified in a given substitution variables dictionary.

Parameters:
variablesThe substitution variables dictionary. The dictionary must contain key-value pairs for all variables in the receiver.
Returns:
A copy of the receiver with the receiver’s variables substituted by values specified in variables.

Reimplemented in CPComparisonPredicate, and CPCompoundPredicate.

Definition at line 106 of file CPPredicate.j.

+ (CPPredicate) predicateWithValue: (BOOL)  value

Creates and returns a predicate that always evaluates to a given value.

Parameters:
valueThe value to which the new predicate should evaluate.
Returns:
A predicate that always evaluates to value.

Definition at line 116 of file CPPredicate.j.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines