<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextInput",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextInput"
  },
  "title" : "NSTextInput"
}
-->

# NSTextInput

A set of methods that text views need to implement to interact properly with the text input management system.

```
protocol NSTextInput
```

## Overview> Important:
> ``doc://com.apple.appkit/documentation/AppKit/NSTextInput`` protocol is slated for deprecation. Please use the ``doc://com.apple.appkit/documentation/AppKit/NSTextInputClient`` protocol instead.

`NSTextView` and its abstract superclass `NSText` are the only classes included in Cocoa that implement `NSTextInput`. To create another text view class, you can either subclass `NSTextView` (and not `NSText`, for historical reasons), or subclass `NSView` and implement the `NSTextInput` protocol.

> Important:
> Methods specific to the `NSTextInput` protocol are intended for dealing with text input and generally are not suitable for other purposes.

## Topics

### Marked text

[`-  hasMarkedText`](/documentation/AppKit/NSTextInput/hasMarkedText)

Returns a Boolean value indicating whether or not the receiver has marked text.

[`-  markedRange`](/documentation/AppKit/NSTextInput/markedRange)

Returns the range of the marked text.

[`-  selectedRange`](/documentation/AppKit/NSTextInput/selectedRange)

Returns the range of selected text.

[`-  setMarkedText:selectedRange:`](/documentation/AppKit/NSTextInput/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.

[`-  unmarkText`](/documentation/AppKit/NSTextInput/unmarkText)

Removes any marking from pending input text and disposes of the marked text as it wishes. The text view should accept the marked text as if it had been inserted normally.

[`-  validAttributesForMarkedText`](/documentation/AppKit/NSTextInput/validAttributesForMarkedText)

Returns an array of names for the attributes supported by the receiver.

### Text storage

[`-  attributedSubstringFromRange:`](/documentation/AppKit/NSTextInput/attributedSubstringFromRange:)

Returns an attributed string derived from the given range in the receiver’s text storage.

[`-  insertText:`](/documentation/AppKit/NSTextInput/insertText:)

Inserts the given string into the receiver’s text storage.

### Character coordinates

[`-  characterIndexForPoint:`](/documentation/AppKit/NSTextInput/characterIndexForPoint:)

Returns the index of the character whose frame rectangle includes the given point.

[`-  firstRectForCharacterRange:`](/documentation/AppKit/NSTextInput/firstRectForCharacterRange:)

Returns the first frame rectangle for characters in the given range, in screen coordinates.

### Key bindings

[`-  doCommandBySelector:`](/documentation/AppKit/NSTextInput/doCommandBySelector:)

Invokes the given selector if possible.

### Other

[`-  conversationIdentifier`](/documentation/AppKit/NSTextInput/conversationIdentifier)

Returns a number used to identify the receiver’s context to the input server.

## Relationships

### Conforming Types

[`NSTextView`](/documentation/AppKit/NSTextView)

---

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)