---
title: "compare(_:toRange:document:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextsearching-3wkjv/compare(_:torange:document:)"
---

# compare(_:toRange:document:)

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

## Declaration

```swift
func compare(_ foundRange: UITextRange, toRange: UITextRange, document: Self.DocumentIdentifier?) -> ComparisonResult
```

## 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

Return Value Returns the result of comparing the two text ranges.

## Discussion

Discussion The system calls this method during a find session to determine which UITextRange to highlight next when a user taps the “next” or “previous” button.

## See Also

### Handling searches

- [performTextSearch(queryString:options:resultAggregator:)](uikit/uitextsearching-3wkjv/performtextsearch(querystring:options:resultaggregator:).md)
- [UITextSearchAggregator](uikit/uitextsearchaggregator-swift.struct.md)
- [compare(document:toDocument:)](uikit/uitextsearching-3wkjv/compare(document:todocument:).md)
- [DocumentIdentifier](uikit/uitextsearching-3wkjv/documentidentifier.md)
