NSComparisonPredicate Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.4 and later. |
| Companion guide | |
| Declared in | NSComparisonPredicate.h |
Overview
NSComparisonPredicate is a subclass of NSPredicate that you use to compare expressions.
You use comparison predicates to compare the results of two expressions. You create a comparison predicate with an operator, a left expression, and a right expression. You represent the expressions using instances of the NSExpression class. When you evaluate the predicate, it returns as a BOOL value the result of invoking the operator with the results of evaluating the expressions.
Tasks
Creating Comparison Predicates
-
+ predicateWithLeftExpression:rightExpression:customSelector: -
+ predicateWithLeftExpression:rightExpression:modifier:type:options: -
– initWithLeftExpression:rightExpression:customSelector: -
– initWithLeftExpression:rightExpression:modifier:type:options:
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.
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
BOOLvalue.
Return Value
A new predicate formed by combining the left and right expressions using selector.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hpredicateWithLeftExpression: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.
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”). For no options, pass
0.
Return Value
A new predicate of type type formed by combining the given left and right expressions using the modifier and options.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hInstance Methods
comparisonPredicateModifier
Returns the comparison predicate modifier for the receiver.
Return Value
The comparison predicate modifier for the receiver.
Discussion
The default value is NSDirectPredicateModifier.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hcustomSelector
Returns the selector for the receiver.
Return Value
The selector for the receiver, or NULL if there is none.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hinitWithLeftExpression:rightExpression:customSelector:
Initializes a predicate formed by combining given left and right expressions using a given 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
BOOLvalue.
Return Value
The receiver, initialized by combining the left and right expressions using selector.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hinitWithLeftExpression: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.
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”). For no options, pass
0.
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
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hleftExpression
Returns the left expression for the receiver.
Return Value
The left expression for the receiver, or nil if there is none.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hoptions
Returns the options that are set for the receiver.
Return Value
The options that are set for the receiver.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hpredicateOperatorType
Returns the predicate type for the receiver.
Return Value
The predicate type for the receiver.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hrightExpression
Returns the right expression for the receiver.
Return Value
The right expression for the receiver, or nil if there is none.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hConstants
NSComparisonPredicateModifier
These constants describe the possible types of modifier for NSComparisonPredicate.
enum {
NSDirectPredicateModifier = 0,
NSAllPredicateModifier,
NSAnyPredicateModifier,
};
typedef NSUInteger NSComparisonPredicateModifier;
Constants
NSDirectPredicateModifierA predicate to compare directly the left and right hand sides.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSAllPredicateModifierA 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
NOwhen it finds the first mismatch—orYESif all match.Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSAnyPredicateModifierA 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
YESwhen it finds the first match—orNOif no match is foundAvailable in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.hNSComparisonPredicate Options
These constants describe the possible types of string comparison for NSComparisonPredicate. These options are supported for LIKE as well as all of the equality/comparison operators.
enum {
NSCaseInsensitivePredicateOption = 0x01,
NSDiacriticInsensitivePredicateOption = 0x02,
NSNormalizedPredicateOption = 0x04,
NSLocaleSensitivePredicateOption = 0x08
};
typedef NSUInteger NSComparisonPredicateOptions;
Constants
NSCaseInsensitivePredicateOptionA case-insensitive predicate.
You represent this option in a predicate format string using a
[c]following a string operation (for example,"NeXT" like[c] "next").Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSDiacriticInsensitivePredicateOptionA diacritic-insensitive predicate.
You represent this option in a predicate format string using a
[d]following a string operation (for example,"naïve" like[d] "naive").Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSNormalizedPredicateOptionIndicates that the strings to be compared have been preprocessed.
This option supersedes
NSCaseInsensitivePredicateOptionandNSDiacriticInsensitivePredicateOption, and is intended as a performance optimization option.You represent this option in a predicate format string using a
[n]following a string operation (for example,"WXYZlan" matches[n] ".lan").Available in OS X v10.7 and later.
Declared in
NSComparisonPredicate.h.NSLocaleSensitivePredicateOptionIndicates that strings to be compared using
<,<=,=,=>,>should be handled in a locale-aware fashion.You represent this option in a predicate format string using a
[l]following one of the<,<=,=,=>,>operators (for example,"straße" >[l] "strasse").
Availability
- Available in OS X v10.7 and later.
Declared In
NSComparisonPredicate.hNSPredicateOperatorType
Defines the type of comparison for NSComparisonPredicate.
enum {
NSLessThanPredicateOperatorType = 0,
NSLessThanOrEqualToPredicateOperatorType,
NSGreaterThanPredicateOperatorType,
NSGreaterThanOrEqualToPredicateOperatorType,
NSEqualToPredicateOperatorType,
NSNotEqualToPredicateOperatorType,
NSMatchesPredicateOperatorType,
NSLikePredicateOperatorType,
NSBeginsWithPredicateOperatorType,
NSEndsWithPredicateOperatorType,
NSInPredicateOperatorType,
NSCustomSelectorPredicateOperatorType,
NSContainsPredicateOperatorType,
NSBetweenPredicateOperatorType
};
typedef NSUInteger NSPredicateOperatorType;
Constants
NSLessThanPredicateOperatorTypeA less-than predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSLessThanOrEqualToPredicateOperatorTypeA less-than-or-equal-to predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSGreaterThanPredicateOperatorTypeA greater-than predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSGreaterThanOrEqualToPredicateOperatorTypeA greater-than-or-equal-to predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSEqualToPredicateOperatorTypeAn equal-to predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSNotEqualToPredicateOperatorTypeA not-equal-to predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSMatchesPredicateOperatorTypeA full regular expression matching predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSLikePredicateOperatorTypeA simple subset of the MATCHES predicate, similar in behavior to SQL
LIKE.Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSBeginsWithPredicateOperatorTypeA begins-with predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSEndsWithPredicateOperatorTypeAn ends-with predicate.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSInPredicateOperatorTypeA predicate to determine if the left hand side is in the right hand side.
For strings, returns
YESif the left hand side is a substring of the right hand side . For collections, returnsYESif the left hand side is in the right hand side .Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSCustomSelectorPredicateOperatorTypeA predicate that uses a custom selector that takes a single argument and returns a
BOOLvalue.The selector is invoked on the left hand side with the right hand side as the argument.
Available in OS X v10.4 and later.
Declared in
NSComparisonPredicate.h.NSContainsPredicateOperatorTypeA predicate to determine if the left hand side contains the right hand side.
Returns
YESif[lhs contains rhs]; the left hand side must be anNSExpressionobject that evaluates to a collectionAvailable in OS X v10.5 and later.
Declared in
NSComparisonPredicate.h.NSBetweenPredicateOperatorTypeA predicate to determine if the right hand side lies at or between bounds specified by the left hand side.
Returns
YESif[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 OS X v10.5 and later.
Declared in
NSComparisonPredicate.h.
Availability
- Available in OS X v10.4 and later.
Declared In
NSComparisonPredicate.h© 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-05-14)