<!--
{
  "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/compareFoundRange:toRange:inDocument:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextSearching(im)compareFoundRange:toRange:inDocument:"
  },
  "title" : "compareFoundRange:toRange:inDocument:"
}
-->

# compareFoundRange:toRange:inDocument:

Compares ranges from the set of matches the aggregator provides to determine navigation order.

```
- (NSComparisonResult) compareFoundRange:(UITextRange *) foundRange toRange:(UITextRange *) toRange inDocument:(UITextSearchDocumentIdentifier) document;
```

## Parameters

`foundRange`

The range of characters in a text container to compare from.

`toRange`

The range of characters in a text container to compare to.

`document`

A string that uniquely identifies the document containing the text ranges. `Nil` when searching a single document.

## Return Value

Returns the result of comparing the two text ranges.

## Discussion

The system calls this method during a find session to determine which [`UITextRange`](/documentation/UIKit/UITextRange) to highlight next when a user taps the “next” or “previous” button.

---

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)