<!--
{
  "availability" : [
    "iOS: 17.4.0 -",
    "iPadOS: 17.4.0 -",
    "tvOS: 17.4.0 -",
    "visionOS: 1.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "BrowserEngineKit",
  "identifier" : "/documentation/BrowserEngineKit/BETextInput/replaceText(_:withText:options:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "BrowserEngineKit"
    ],
    "preciseIdentifier" : "c:objc(pl)BETextInput(im)replaceText:withText:options:completionHandler:"
  },
  "title" : "replaceText(_:withText:options:completionHandler:)"
}
-->

# replaceText(_:withText:options:completionHandler:)

Replace the specified text preceding the current selection.

```
func replaceText(_ originalText: String, withText replacementText: String, options: BETextReplacementOptions = [], completionHandler: @escaping @Sendable ([UITextSelectionRect]) -> Void)
```

```
func replaceText(_ originalText: String, withText replacementText: String, options: BETextReplacementOptions = []) async -> [UITextSelectionRect]
```

## Discussion

Completion handler should be invoked with the rects representing the replacementText.  If the replaceText
could not be completed succesfully, such as when the originalText no longer matches the current text, then
the completion handler should be invoked with an empty array.

---

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)