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

# replace(foundTextRange:document:withText:)

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

```
func replace(foundTextRange: UITextRange, document: Self.DocumentIdentifier?, withText: String)
```

## Parameters

`foundTextRange`

The text range to replace.

`document`

A string that uniquely identifies a document when searching multiple documents, or `nil` when searching a single document.

`withText`

The string to replace the text with.

## Discussion

When [`supportsTextReplacement`](/documentation/UIKit/UITextSearching-3wkjv/supportsTextReplacement) returns `YES,` the system calls this method during a find session to request a text range to replace.

---

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)