<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextSearching"
  },
  "title" : "UITextSearching"
}
-->

# UITextSearching

The methods you use on a find session’s searchable objects to perform search operations and decorate the found text results.

```
@protocol UITextSearching <NSObject>
```

## Overview

Implement this protocol on the class that encapsulates the searchable content for your view. This allows you to use an instance of [`UITextSearchingFindSession`](/documentation/UIKit/UITextSearchingFindSession) to manage the session for a find interaction.

## Topics

### Handling searches

[`- (void) performTextSearchWithQueryString:(NSString *) string usingOptions:(UITextSearchOptions *) options resultAggregator:(id<UITextSearchAggregator>) aggregator;`](/documentation/UIKit/UITextSearching-53wjq/performTextSearchWithQueryString:usingOptions:resultAggregator:)

Searches for ranges of text matching the string across all searchable documents and collects results in the aggregator.

[`@protocol UITextSearchAggregator <NSObject>`](/documentation/UIKit/UITextSearchAggregator-c.protocol)

The methods you use on a find session’s aggregator to collect matching text ranges for a search.

[`- (NSComparisonResult) compareFoundRange:(UITextRange *) foundRange toRange:(UITextRange *) toRange inDocument:(UITextSearchDocumentIdentifier) document;`](/documentation/UIKit/UITextSearching-53wjq/compareFoundRange:toRange:inDocument:)

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

[`- (NSComparisonResult) compareOrderFromDocument:(UITextSearchDocumentIdentifier) fromDocument toDocument:(UITextSearchDocumentIdentifier) toDocument;`](/documentation/UIKit/UITextSearching-53wjq/compareOrderFromDocument:toDocument:)

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

[`typedef id<NSCopying,NSObject> UITextSearchDocumentIdentifier;`](/documentation/UIKit/UITextSearchDocumentIdentifier)

A string that uniquely identifies a specific document when searching for matching text across multiple documents.

### Displaying results

[`- (void) decorateFoundTextRange:(UITextRange *) range inDocument:(UITextSearchDocumentIdentifier) document usingStyle:(UITextSearchFoundTextStyle) style;`](/documentation/UIKit/UITextSearching-53wjq/decorateFoundTextRange:inDocument:usingStyle:)

Applies the style to a specific text range to indicate found and highlighted results.

[`- (void) clearAllDecoratedFoundText;`](/documentation/UIKit/UITextSearching-53wjq/clearAllDecoratedFoundText)

Clears the style from all found and highlighted results.

[`- (void) willHighlightFoundTextRange:(UITextRange *) range inDocument:(UITextSearchDocumentIdentifier) document;`](/documentation/UIKit/UITextSearching-53wjq/willHighlightFoundTextRange:inDocument:)

Informs the searchable object when the highlighted search result is about to change.

[`- (void) scrollRangeToVisible:(UITextRange *) range inDocument:(UITextSearchDocumentIdentifier) document;`](/documentation/UIKit/UITextSearching-53wjq/scrollRangeToVisible:inDocument:)

Scrolls to the containing view to make the text range visible.

### Identifying selected text

[`@property (readonly, nullable) UITextRange * selectedTextRange;`](/documentation/UIKit/UITextSearching-53wjq/selectedTextRange)

The range of selected text in a document.

[`@property (readonly, nullable) UITextSearchDocumentIdentifier selectedTextSearchDocument;`](/documentation/UIKit/UITextSearching-53wjq/selectedTextSearchDocument)

The object that uniquely identifies the specific document with selected text.

### Handling replacements

[`@property (nonatomic, readonly) BOOL supportsTextReplacement;`](/documentation/UIKit/UITextSearching-53wjq/supportsTextReplacement)

A Boolean value that indicates whether the searchable object supports replacing text.

[`- (void) replaceFoundTextInRange:(UITextRange *) range inDocument:(UITextSearchDocumentIdentifier) document withText:(NSString *) replacementText;`](/documentation/UIKit/UITextSearching-53wjq/replaceFoundTextInRange:inDocument:withText:)

Informs the searchable object to replace the text range for the highlighted search result.

[`- (void) replaceAllOccurrencesOfQueryString:(NSString *) queryString usingOptions:(UITextSearchOptions *) options withText:(NSString *) replacementText;`](/documentation/UIKit/UITextSearching-53wjq/replaceAllOccurrencesOfQueryString:usingOptions:withText:)

Informs the searchable object to replace all matching text across all searchable documents.

[`- (BOOL) shouldReplaceFoundTextInRange:(UITextRange *) range inDocument:(UITextSearchDocumentIdentifier) document withText:(NSString *) replacementText;`](/documentation/UIKit/UITextSearching-53wjq/shouldReplaceFoundTextInRange:inDocument:withText:)

Determines whether the searchable object allows replacement of the text range you provide.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

### Conforming Types

[`UITextView`](/documentation/UIKit/UITextView)

---

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)