<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextSearching-3wkjv/compare(document:toDocument:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "s:5UIKit15UITextSearchingP7compare8document10toDocumentSo18NSComparisonResultV0G10IdentifierQz_AJtF"
  },
  "title" : "compare(document:toDocument:)"
}
-->

# compare(document:toDocument:)

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

```
func compare(document: Self.DocumentIdentifier, toDocument: Self.DocumentIdentifier) -> ComparisonResult
```

## Parameters

`document`

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)