---
title: "setMarkedText(_:selectedRange:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextinput/setmarkedtext(_:selectedrange:)"
---

# setMarkedText(_:selectedRange:)

Inserts the provided text and marks it to indicate that it is part of an active input session.

## Declaration

```swift
func setMarkedText(_ markedText: String?, selectedRange: NSRange)
```

## Parameters

- `markedText`: The text to be marked.
- `selectedRange`: A range within markedText that indicates the current selection. This range is always relative to markedText.

## Discussion

Discussion Setting marked text either replaces the existing marked text or, if none is present, inserts it in place of the current selection.

## See Also

### Working with marked and selected text

- [selectedTextRange](uikit/uitextinput/selectedtextrange.md)
- [markedTextRange](uikit/uitextinput/markedtextrange.md)
- [markedTextStyle](uikit/uitextinput/markedtextstyle.md)
- [setAttributedMarkedText(_:selectedRange:)](uikit/uitextinput/setattributedmarkedtext(_:selectedrange:).md)
- [unmarkText()](uikit/uitextinput/unmarktext().md)
- [selectionAffinity](uikit/uitextinput/selectionaffinity.md)
