<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.6.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextInput/setMarkedText:selectedRange:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextInput(im)setMarkedText:selectedRange:"
  },
  "title" : "setMarkedText:selectedRange:"
}
-->

# setMarkedText:selectedRange:

Replaces currently marked text in the receiver’s text storage with the given string and sets the selection to the given range, computed from the beginning of the marked text.

```
- (void) setMarkedText:(id) string selectedRange:(NSRange) selRange;
```

## Parameters

`string`

Either an `NSString` or an `NSAttributedString` object; must not be `nil`.

`selRange`

The range within `aString` to set as the selection.

## Discussion

If there is no marked text, the current selection is replaced. If there is no selection, the string is inserted at the insertion point.

---

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)