<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextDocumentProxy/setMarkedText(_:selectedRange:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextDocumentProxy(im)setMarkedText:selectedRange:"
  },
  "title" : "setMarkedText(_:selectedRange:)"
}
-->

# setMarkedText(_:selectedRange:)

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

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

## Discussion

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

---

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)