setMarkedText(_:selectedRange:replacementRange:)
Replaces a specified range in the receiver’s text storage with the given string and sets the selection.
Declaration
func setMarkedText(_ string: Any, selectedRange: NSRange, replacementRange: NSRange)Parameters
- string:
The string to insert. Can be either an
NSStringorNSAttributedStringinstance. - selectedRange:
The range to set as the selection, computed from the beginning of the inserted string.
- replacementRange:
The range to replace, computed from the beginning of the marked text.
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.
When aString is an NSString object, the receiver is expected to render the marked text with distinguishing appearance (for example, NSTextView renders with markedTextAttributes).