---
title: "replace(_:withText:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextinput/replace(_:withtext:)"
---

# replace(_:withText:)

Replaces the text in a document that is in the specified range.

## Declaration

```swift
func replace(_ range: UITextRange, withText text: String)
```

## Parameters

- `range`: A range of text in a document.
- `text`: A string to replace the text in range.

## See Also

### Replacing and returning text

- [text(in:)](uikit/uitextinput/text(in:).md)
- [shouldChangeText(in:replacementText:)](uikit/uitextinput/shouldchangetext(in:replacementtext:).md)
