NSComparisonMethods Protocol Reference

(informal protocol)

Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Declared in
NSScriptWhoseTests.h

Overview

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.

Tasks

Performing Comparisons

Instance Methods

doesContain:

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

- (BOOL)doesContain:(id)object
Parameters
object

The object to search for in the receiver.

Return Value

YES if the receiver contains object, otherwise NO.

Discussion

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

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

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h

isCaseInsensitiveLike:

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.

- (BOOL)isCaseInsensitiveLike:(NSString *)aString
Parameters
aString

The string with which to compare the receiver.

Return Value

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

Discussion

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

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

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h

isEqualTo:

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

- (BOOL)isEqualTo:(id)object
Parameters
object

The object with which to compare the receiver.

Return Value

YES if the receiver is equal to object, otherwise NO. In effect returns NO 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 YES if an isEqualTo: message sent to the same object would return YES.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h

isGreaterThan:

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

- (BOOL)isGreaterThan:(id)object
Parameters
object

The object with which to compare the receiver.

Return Value

YES if the receiver is greater than object, otherwise NO.

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 YES if a compare: message sent to the same object would return NSOrderedDescending.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h

isGreaterThanOrEqualTo:

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

- (BOOL)isGreaterThanOrEqualTo:(id)object
Parameters
object

The object with which to compare the receiver.

Return Value

YES if the receiver is greater than or equal to object, otherwise NO.

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 YES if a compare: message sent to the same object would return NSOrderedSame or NSOrderedDescending.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h

isLessThan:

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

- (BOOL)isLessThan:(id)object
Parameters
object

The object with which to compare the receiver.

Return Value

YES if the receiver is less than object, otherwise NO.

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 YES if a compare: message sent to the same object would return NSOrderedAscending.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h

isLessThanOrEqualTo:

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

- (BOOL)isLessThanOrEqualTo:(id)object
Parameters
object

The object with which to compare the receiver.

Return Value

YES if the receiver is less than or equal to object, otherwise NO.

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 YES if a compare: message sent to the same object would return NSOrderedAscending or NSOrderedSame.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h

isLike:

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

- (BOOL)isLike:(NSString *)object
Parameters
object

The object with which to compare the receiver.

Return Value

YES if the receiver is considered to be “like” object, otherwise NO.

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 NO. NSString also provides an implementation of this method, which returns YES if the receiver matches a pattern described by object.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h

isNotEqualTo:

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

- (BOOL)isNotEqualTo:(id)object
Parameters
object

The object with which to compare the receiver.

Return Value

YES if the receiver is not equal to object, otherwise NO.

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 YES if an isEqual: message sent to the same object would return NO.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSScriptWhoseTests.h