<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextSearching-53wjq/compareOrderFromDocument:toDocument:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextSearching(im)compareOrderFromDocument:toDocument:"
  },
  "title" : "compareOrderFromDocument:toDocument:"
}
-->

# compareOrderFromDocument:toDocument:

Compares documents containing matching ranges from the set the aggregator provides to determine navigation order.

```
- (NSComparisonResult) compareOrderFromDocument:(UITextSearchDocumentIdentifier) fromDocument toDocument:(UITextSearchDocumentIdentifier) toDocument;
```

## Parameters

`fromDocument`

A string that uniquely identifies the document to compare from.

`toDocument`

A string that uniquely identifies the document to compare to.

## Return Value

Returns the result of comparing the two documents.

## Discussion

The system calls this method during a find session to determine which document’s ranges to highlight next when a user taps the “next” or “previous” button. Return <doc://com.apple.documentation/documentation/Foundation/ComparisonResult/orderedAscending> if the text ranges found in the `fromDocument` come before those found in the `toDocument` in your view. Otherwise, return <doc://com.apple.documentation/documentation/Foundation/ComparisonResult/orderedDescending>.

The system only calls this method if you provide document identifiers to the session’s result aggregator.

---

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)