Mac Developer Library

Developer

Foundation Framework Reference NSComparisonMethods Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSComparisonMethods

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.0 and later.

This informal protocol defines a set of default comparison methods useful for the comparisons in NSSpecifierTest.

If you have scriptable objects that need to perform comparisons for scripting purposes, you may need to implement some of the methods declared in NSScriptingComparisonMethods. The default implementation provided for many of these methods by NSObject is appropriate for objects that implement a single comparison method whose selector, signature, and description match the following:

  • - (NSComparisonResult)compare:(id)object;

This method should return NSOrderedAscending if the receiver is less than object, NSOrderedDescending if the receiver is greater than object, and NSOrderedSame if the receiver and object are equal. For example, NSString does not implement most of the methods declared in this informal protocol, but NSString objects still handle messages conforming to this protocol properly because NSString implements a compare: method that meets the necessary requirements. Cocoa also includes appropriate compare: method implementations for the NSDate, NSDecimalNumber, and NSValue classes.

  • Returns a Boolean value that indicates whether the receiver contains a given object.

    Declaration

    Swift

    func doesContain(_ object: AnyObject) -> Bool

    Objective-C

    - (BOOL)doesContain:(id)object

    Parameters

    object

    The object to search for in the receiver.

    Return Value

    YEStrue if the receiver contains object, otherwise NOfalse.

    Discussion

    Currently, doesContain: messages are never sent to any object from within Cocoa itself.

    The default implementation for this method provided by NSObject returns YEStrue if the receiver is actually an NSArray object and an indexOfObjectIdenticalTo: message sent to the same object would return something other than NSNotFound.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether receiver is considered to be “like” a given string when the case of characters in the receiver is ignored.

    Declaration

    Swift

    func isCaseInsensitiveLike(_ aString: String!) -> Bool

    Objective-C

    - (BOOL)isCaseInsensitiveLike:(NSString *)aString

    Parameters

    aString

    The string with which to compare the receiver.

    Return Value

    YEStrue if the receiver is considered to be “like” aString when the case of characters in the receiver is ignored, otherwise NOfalse.

    Discussion

    Currently, isCaseInsensitiveLike: messages are never sent to any object from within Cocoa itself.

    The default implementation for this method provided by NSObject returns NOfalse. NSString also provides an implementation of this method, which returns YEStrue if the receiver matches a pattern described by aString, ignoring the case of the characters in the receiver.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver is equal to another given object.

    Declaration

    Swift

    func isEqualTo(_ object: AnyObject?) -> Bool

    Objective-C

    - (BOOL)isEqualTo:(id)object

    Parameters

    object

    The object with which to compare the receiver.

    Return Value

    YEStrue if the receiver is equal to object, otherwise NOfalse. In effect returns NOfalse if receiver is nil.

    Discussion

    During the evaluation of an NSWhoseSpecifier object that contains a test whose operator is NSEqualToComparison, an isEqualTo: message may be sent to each potentially specified object, if neither the potentially specified object nor the object being tested against implements a scriptingIsEqualTo: method.

    The default implementation for this method provided by NSObject returns YEStrue if an isEqualTo: message sent to the same object would return YEStrue.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver is greater than another given object.

    Declaration

    Swift

    func isGreaterThan(_ object: AnyObject!) -> Bool

    Objective-C

    - (BOOL)isGreaterThan:(id)object

    Parameters

    object

    The object with which to compare the receiver.

    Return Value

    YEStrue if the receiver is greater than object, otherwise NOfalse.

    Discussion

    During the evaluation of an NSWhoseSpecifier object that contains a test whose operator is NSGreaterThanComparison, an isGreaterThan: message may be sent to each potentially specified object, if the potentially specified object does not implement a scriptingIsGreaterThan: method and the object being tested against does not implement a scriptingIsLessThanOrEqualTo: method.

    The default implementation for this method provided by NSObject returns YEStrue if a compare: message sent to the same object would return NSOrderedDescending.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver is greater than or equal to another given object.

    Declaration

    Swift

    func isGreaterThanOrEqualTo(_ object: AnyObject!) -> Bool

    Objective-C

    - (BOOL)isGreaterThanOrEqualTo:(id)object

    Parameters

    object

    The object with which to compare the receiver.

    Return Value

    YEStrue if the receiver is greater than or equal to object, otherwise NOfalse.

    Discussion

    During the evaluation of an NSWhoseSpecifier object that contains a test whose operator is NSGreaterThanOrEqualToComparison, anisGreaterThanOrEqualTo: message may be sent to each potentially specified object, if the potentially specified object does not implement a scriptingIsGreaterThanOrEqualTo: method and the object being tested against does not implement a scriptingIsLessThan: method.

    The default implementation for this method provided by NSObject returns YEStrue if a compare: message sent to the same object would return NSOrderedSame or NSOrderedDescending.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver is less than another given object.

    Declaration

    Swift

    func isLessThan(_ object: AnyObject!) -> Bool

    Objective-C

    - (BOOL)isLessThan:(id)object

    Parameters

    object

    The object with which to compare the receiver.

    Return Value

    YEStrue if the receiver is less than object, otherwise NOfalse.

    Discussion

    During the evaluation of an NSWhoseSpecifier object that contains a test whose operator is NSLessThanComparison, an isLessThan: message may be sent to each potentially specified object, if the potentially specified object does not implement a scriptingIsLessThan: method and the object being tested against does not implement a scriptingIsGreaterThanOrEqualTo: method.

    The default implementation for this method provided by NSObject method returns YEStrue if a compare: message sent to the same object would return NSOrderedAscending.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver is less than or equal to another given object.

    Declaration

    Swift

    func isLessThanOrEqualTo(_ object: AnyObject!) -> Bool

    Objective-C

    - (BOOL)isLessThanOrEqualTo:(id)object

    Parameters

    object

    The object with which to compare the receiver.

    Return Value

    YEStrue if the receiver is less than or equal to object, otherwise NOfalse.

    Discussion

    During the evaluation of an NSWhoseSpecifier object that contains a test whose operator is NSLessThanOrEqualToComparison, an isLessThanOrEqualTo: message may be sent to each potentially specified object, if the potentially specified object does not implement a scriptingIsLessThanOrEqualTo: method and the object being tested against does not implement a scriptingIsGreaterThan: method.

    The default implementation for this method provided by NSObject method returns YEStrue if a compare: message sent to the same object would return NSOrderedAscending or NSOrderedSame.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver is "like" another given object.

    Declaration

    Swift

    func isLike(_ object: String!) -> Bool

    Objective-C

    - (BOOL)isLike:(NSString *)object

    Parameters

    object

    The object with which to compare the receiver.

    Return Value

    YEStrue if the receiver is considered to be “like” object, otherwise NOfalse.

    Discussion

    Currently, isLike: messages are never sent to any object from within Cocoa itself.

    The default implementation for this method provided by NSObject method returns NOfalse. NSString also provides an implementation of this method, which returns YEStrue if the receiver matches a pattern described by object.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver is not equal to another given object.

    Declaration

    Swift

    func isNotEqualTo(_ object: AnyObject!) -> Bool

    Objective-C

    - (BOOL)isNotEqualTo:(id)object

    Parameters

    object

    The object with which to compare the receiver.

    Return Value

    YEStrue if the receiver is not equal to object, otherwise NOfalse.

    Discussion

    Currently, isNotEqualTo: messages are never sent to any object from within Cocoa itself.

    The default implementation for this method provided by NSObject method returns YEStrue if an isEqual: message sent to the same object would return NOfalse.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.