Mac Developer Library

Developer

Foundation Framework Reference NSComparisonPredicate Class Reference

Options
Deployment Target:

On This Page
Language:

NSComparisonPredicate

Inheritance


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.4 and later.

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.

  • The comparison predicate modifier for the receiver. (read-only)

    Declaration

    Swift

    var comparisonPredicateModifier: NSComparisonPredicateModifier { get }

    Objective-C

    @property(readonly) NSComparisonPredicateModifier comparisonPredicateModifier

    Discussion

    The default value is NSDirectPredicateModifier.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • The selector for the receiver. (read-only)

    Declaration

    Swift

    var customSelector: Selector { get }

    Objective-C

    @property(readonly) SEL customSelector

    Discussion

    NULL if there is none.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • The right expression for the receiver. (read-only)

    Declaration

    Swift

    var rightExpression: NSExpression { get }

    Objective-C

    @property(readonly, retain) NSExpression *rightExpression

    Discussion

    nil if there is none.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • The left expression for the receiver. (read-only)

    Declaration

    Swift

    var leftExpression: NSExpression { get }

    Objective-C

    @property(readonly, retain) NSExpression *leftExpression

    Discussion

    nil if there is none.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • options options Property

    The options that are set for the receiver. (read-only)

    Declaration

    Swift

    var options: NSComparisonPredicateOptions { get }

    Objective-C

    @property(readonly) NSComparisonPredicateOptions options

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • The predicate type for the receiver. (read-only)

    Declaration

    Swift

    var predicateOperatorType: NSPredicateOperatorType { get }

    Objective-C

    @property(readonly) NSPredicateOperatorType predicateOperatorType

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

Data Types

  • These constants describe the possible types of modifier for NSComparisonPredicate.

    Declaration

    Swift

    enum NSComparisonPredicateModifier : UInt { case DirectPredicateModifier case AllPredicateModifier case AnyPredicateModifier }

    Objective-C

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

    Constants

    • DirectPredicateModifier

      NSDirectPredicateModifier

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

      Available in OS X v10.4 and later.

    • AllPredicateModifier

      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 NOfalse when it finds the first mismatch—€”or YEStrue if all match.

      Available in OS X v10.4 and later.

    • AnyPredicateModifier

      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 YEStrue when it finds the first match—or NOfalse if no match is found

      Available in OS X v10.4 and later.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.

  • 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.

    Declaration

    Swift

    struct NSComparisonPredicateOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var CaseInsensitivePredicateOption: NSComparisonPredicateOptions { get } static var DiacriticInsensitivePredicateOption: NSComparisonPredicateOptions { get } static var NormalizedPredicateOption: NSComparisonPredicateOptions { get } }

    Objective-C

    enum { NSCaseInsensitivePredicateOption = 0x01, NSDiacriticInsensitivePredicateOption = 0x02, NSNormalizedPredicateOption = 0x04, NSLocaleSensitivePredicateOption = 0x08 }; typedef NSUInteger NSComparisonPredicateOptions;

    Constants

    • CaseInsensitivePredicateOption

      NSCaseInsensitivePredicateOption

      A 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.

    • DiacriticInsensitivePredicateOption

      NSDiacriticInsensitivePredicateOption

      A 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.

    • NormalizedPredicateOption

      NSNormalizedPredicateOption

      Indicates that the strings to be compared have been preprocessed.

      This option supersedes NSCaseInsensitivePredicateOption and NSDiacriticInsensitivePredicateOption, 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.6 and later.

    • NSLocaleSensitivePredicateOption

      NSLocaleSensitivePredicateOption

      Indicates 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").

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • Defines the type of comparison for NSComparisonPredicate.

    Declaration

    Swift

    enum NSPredicateOperatorType : UInt { case LessThanPredicateOperatorType case LessThanOrEqualToPredicateOperatorType case GreaterThanPredicateOperatorType case GreaterThanOrEqualToPredicateOperatorType case EqualToPredicateOperatorType case NotEqualToPredicateOperatorType case MatchesPredicateOperatorType case LikePredicateOperatorType case BeginsWithPredicateOperatorType case EndsWithPredicateOperatorType case InPredicateOperatorType case CustomSelectorPredicateOperatorType case ContainsPredicateOperatorType case BetweenPredicateOperatorType }

    Objective-C

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

    Constants

    • LessThanPredicateOperatorType

      NSLessThanPredicateOperatorType

      A less-than predicate.

      Available in OS X v10.4 and later.

    • LessThanOrEqualToPredicateOperatorType

      NSLessThanOrEqualToPredicateOperatorType

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

      Available in OS X v10.4 and later.

    • GreaterThanPredicateOperatorType

      NSGreaterThanPredicateOperatorType

      A greater-than predicate.

      Available in OS X v10.4 and later.

    • GreaterThanOrEqualToPredicateOperatorType

      NSGreaterThanOrEqualToPredicateOperatorType

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

      Available in OS X v10.4 and later.

    • EqualToPredicateOperatorType

      NSEqualToPredicateOperatorType

      An equal-to predicate.

      Available in OS X v10.4 and later.

    • NotEqualToPredicateOperatorType

      NSNotEqualToPredicateOperatorType

      A not-equal-to predicate.

      Available in OS X v10.4 and later.

    • MatchesPredicateOperatorType

      NSMatchesPredicateOperatorType

      A full regular expression matching predicate.

      Available in OS X v10.4 and later.

    • LikePredicateOperatorType

      NSLikePredicateOperatorType

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

      Available in OS X v10.4 and later.

    • BeginsWithPredicateOperatorType

      NSBeginsWithPredicateOperatorType

      A begins-with predicate.

      Available in OS X v10.4 and later.

    • EndsWithPredicateOperatorType

      NSEndsWithPredicateOperatorType

      An ends-with predicate.

      Available in OS X v10.4 and later.

    • InPredicateOperatorType

      NSInPredicateOperatorType

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

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

      Available in OS X v10.4 and later.

    • CustomSelectorPredicateOperatorType

      NSCustomSelectorPredicateOperatorType

      A 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 as the argument.

      Available in OS X v10.4 and later.

    • ContainsPredicateOperatorType

      NSContainsPredicateOperatorType

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

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

      Available in OS X v10.5 and later.

    • BetweenPredicateOperatorType

      NSBetweenPredicateOperatorType

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

      Returns YEStrue 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 OS X v10.5 and later.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.4 and later.