<!--
{
  "documentType" : "article",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/nscomparisonmethods",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "NSComparisonMethods"
}
-->

# NSComparisonMethods

A collection of default comparison methods useful for performing specifier tests.

## Discussion

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:

```objc
- (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.

## Topics

### Performing comparisons

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/doesContain(_:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/isCaseInsensitiveLike(_:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/isEqual(to:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/isGreaterThan(_:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/isGreaterThanOrEqual(to:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/isLessThan(_:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/isLessThanOrEqual(to:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/isLike(_:)>

  <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/isNotEqual(to:)>

## See Also

  [Cocoa Scripting Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_intro/SAppsIntro.html#//apple_ref/doc/uid/TP40002164)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)