Next Page > Hide TOC

NSComparisonPredicate Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in Mac OS X v10.4 and later.
Companion guide
Declared in
NSComparisonPredicate.h
Related sample code

Overview

NSComparisonPredicate is a subclass of NSPredicate used to compare expressions.

Comparison predicates are predicates used to compare the results of two expressions. Comparison predicates take an operator, a left expression, and a right expression, and return as a BOOL the result of invoking the operator with the results of evaluating the expressions. Expressions are represented by instances of the NSExpression class.

Tasks

Constructors

Getting Information About a Comparison Predicate

Class Methods

predicateWithLeftExpression:rightExpression:customSelector:

Returns a new predicate formed by combining the left and right expressions using a given selector.

+ (NSPredicate *)predicateWithLeftExpression:(NSExpression *)lhs rightExpression:(NSExpression *)rhs customSelector:(SEL)selector

Parameters
lhs

The left hand side expression.

rhs

The right hand side expression.

selector

The selector to use for comparison. The method defined by the selector must take a single argument and return a BOOL value.

Return Value

A new predicate formed by combining the left and right expressions using selector.

Availability
Declared In
NSComparisonPredicate.h

predicateWithLeftExpression:rightExpression:modifier:type:options:

Creates and returns a predicate of a given type formed by combining given left and right expressions using a given modifier and options.

+ (NSPredicate *)predicateWithLeftExpression:(NSExpression *)lhs rightExpression:(NSExpression *)rhs modifier:(NSComparisonPredicateModifier)modifier type:(NSPredicateOperatorType)type options:(NSUInteger)options

Parameters
lhs

The left hand expression.

rhs

The right hand expression.

modifier

The modifier to apply.

type

The predicate operator type.

options

The options to apply (see NSComparisonPredicate Options).

Return Value

A new predicate of type type formed by combining the given left and right expressions using the modifier and options.

Availability
Related Sample Code
Declared In
NSComparisonPredicate.h

Instance Methods

comparisonPredicateModifier

Returns the comparison predicate modifier for the receiver.

- (NSComparisonPredicateModifier)comparisonPredicateModifier

Return Value

The comparison predicate modifier for the receiver.

Discussion

The default value is NSDirectPredicateModifier.

Availability
Related Sample Code
Declared In
NSComparisonPredicate.h

customSelector

Returns the selector for the receiver.

- (SEL)customSelector

Return Value

The selector for the receiver, or NULL if there is none.

Availability
Declared In
NSComparisonPredicate.h

initWithLeftExpression:rightExpression:customSelector:

Initializes a predicate formed by combining given left and right expressions using a given selector.

- (id)initWithLeftExpression:(NSExpression *)lhs rightExpression:(NSExpression *)rhs customSelector:(SEL)selector

Parameters
lhs

The left hand expression.

rhs

The right hand expression.

selector

The selector to use. The method defined by the selector must take a single argument and return a BOOL value.

Return Value

The receiver, initialized by combining the left and right expressions using selector.

Availability
Declared In
NSComparisonPredicate.h

initWithLeftExpression:rightExpression:modifier:type:options:

Initializes a predicate to a given type formed by combining given left and right expressions using a given modifier and options.

- (id)initWithLeftExpression:(NSExpression *)lhs rightExpression:(NSExpression *)rhs modifier:(NSComparisonPredicateModifier)modifier type:(NSPredicateOperatorType)type options:(NSUInteger)options

Parameters
lhs

The left hand expression.

rhs

The right hand expression.

modifier

The modifier to apply.

type

The predicate operator type.

options

The options to apply (see NSComparisonPredicate Options).

Return Value

The receiver, initialized to a predicate of type type formed by combining the left and right expressions using the modifier and options.

Availability
Declared In
NSComparisonPredicate.h

leftExpression

Returns the left expression for the receiver.

- (NSExpression *)leftExpression

Return Value

The left expression for the receiver, or nil if there is none.

Availability
Related Sample Code
Declared In
NSComparisonPredicate.h

options

Returns the options that are set for the receiver.

- (NSUInteger)options

Return Value

The options that are set for the receiver.

Availability
Related Sample Code
Declared In
NSComparisonPredicate.h

predicateOperatorType

Returns the predicate type for the receiver.

- (NSPredicateOperatorType)predicateOperatorType

Return Value

The predicate type for the receiver.

Availability
Related Sample Code
Declared In
NSComparisonPredicate.h

rightExpression

Returns the right expression for the receiver.

- (NSExpression *)rightExpression

Return Value

The right expression for the receiver, or nil if there is none.

Availability
Related Sample Code
Declared In
NSComparisonPredicate.h

Constants

NSComparisonPredicateModifier

These constants describe the possible types of modifier for NSComparisonPredicate.

typedef enum {
   NSDirectPredicateModifier = 0,
   NSAllPredicateModifier,
   NSAnyPredicateModifier,
} NSComparisonPredicateModifier;

Constants
NSDirectPredicateModifier

A predicate to compare directly the left and right hand sides.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSAllPredicateModifier

A predicate to compare all entries in the destination of a to-many relationship.

The left hand side must be a collection. The corresponding predicate compares each value in the left hand side with the right hand side, and returns NO when it finds the first mismatch—or YES if all match.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSAnyPredicateModifier

A predicate to match with any entry in the destination of a to-many relationship.

The left hand side must be a collection. The corresponding predicate compares each value in the left hand side against the right hand side and returns YES when it finds the first match—or NO if no match is found

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

Declared In
NSComparisonPredicate.h

NSComparisonPredicate Options

These constants describe the possible types of string comparison for NSComparisonPredicate.

enum {
   NSCaseInsensitivePredicateOption = 0x01,
   NSDiacriticInsensitivePredicateOption = 0x02,
};

Constants
NSCaseInsensitivePredicateOption

A case-insensitive predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSDiacriticInsensitivePredicateOption

A diacritic-insensitive predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

Declared In
NSComparisonPredicate.h

NSPredicateOperatorType

Defines the type of comparison for NSComparisonPredicate.

typedef enum {
   NSLessThanPredicateOperatorType = 0,
   NSLessThanOrEqualToPredicateOperatorType,
   NSGreaterThanPredicateOperatorType,
   NSGreaterThanOrEqualToPredicateOperatorType,
   NSEqualToPredicateOperatorType,
   NSNotEqualToPredicateOperatorType,
   NSMatchesPredicateOperatorType,
   NSLikePredicateOperatorType,
   NSBeginsWithPredicateOperatorType,
   NSEndsWithPredicateOperatorType,
   NSInPredicateOperatorType,
   NSCustomSelectorPredicateOperatorType,
   NSContainsPredicateOperatorType,
   NSBetweenPredicateOperatorType
} NSPredicateOperatorType;

Constants
NSLessThanPredicateOperatorType

A less-than predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSLessThanOrEqualToPredicateOperatorType

A less-than-or-equal-to predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSGreaterThanPredicateOperatorType

A greater-than predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSGreaterThanOrEqualToPredicateOperatorType

A greater-than-or-equal-to predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSEqualToPredicateOperatorType

An equal-to predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSNotEqualToPredicateOperatorType

A not-equal-to predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSMatchesPredicateOperatorType

A full regular expression matching predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSLikePredicateOperatorType

A simple subset of the matches predicate, similar in behavior to SQL LIKE.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSBeginsWithPredicateOperatorType

A begins-with predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSEndsWithPredicateOperatorType

An ends-with predicate.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSInPredicateOperatorType

A predicate to determine if the left hand side is in the right hand side.

For strings, returns YES if the left hand side is a substring of the right hand side . For collections, returns YES if the left hand side is in the right hand side .

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSCustomSelectorPredicateOperatorType

Predicate that uses a custom selector that takes a single argument and returns a BOOL value.

The selector is invoked on the left hand side with the right hand side.

Available in Mac OS X v10.4 and later.

Declared in NSComparisonPredicate.h.

NSContainsPredicateOperatorType

A predicate to determine if the left hand side contains the right hand side.

Returns YES if [lhs contains rhs]; the left hand side must be an NSExpression object that evaluates to a collection

Available in Mac OS X v10.5 and later.

Declared in NSComparisonPredicate.h.

NSBetweenPredicateOperatorType

A predicate to determine if the right hand side lies between bounds specified by the left hand side.

Returns YES if [lhs between rhs]; the right hand side must be an array in which the first element sets the lower bound and the second element the upper, inclusive. Comparison is performed using compare: or the class-appropriate equivalent.

Available in Mac OS X v10.5 and later.

Declared in NSComparisonPredicate.h.

Declared In
NSComparisonPredicate.h

Next Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-04-30)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.