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

# NSTextInputClient

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

```
protocol NSTextInputClient : NSObjectProtocol
```

## Overview

To create another text view class, you can either subclass [`NSTextView`](/documentation/AppKit/NSTextView), or subclass [`NSView`](/documentation/AppKit/NSView) and implement the [`NSTextInputClient`](/documentation/AppKit/NSTextInputClient) protocol.

> Important:
> Methods specific to the ``doc://com.apple.appkit/documentation/AppKit/NSTextInputClient`` protocol are intended for dealing with text input and generally aren’t suitable for other purposes.

## Topics

### Handling marked text

[`hasMarkedText()`](/documentation/AppKit/NSTextInputClient/hasMarkedText())

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

[`markedRange()`](/documentation/AppKit/NSTextInputClient/markedRange())

Returns the range of the marked text.

[`selectedRange()`](/documentation/AppKit/NSTextInputClient/selectedRange())

Returns the range of selected text.

[`setMarkedText(_:selectedRange:replacementRange:)`](/documentation/AppKit/NSTextInputClient/setMarkedText(_:selectedRange:replacementRange:))

Replaces a specified range in the receiver’s text storage with the given string and sets the selection.

[`unmarkText()`](/documentation/AppKit/NSTextInputClient/unmarkText())

Unmarks the marked text.

[`validAttributesForMarkedText()`](/documentation/AppKit/NSTextInputClient/validAttributesForMarkedText())

Returns an array of attribute names recognized by the receiver.

### Storing text

[`attributedString()`](/documentation/AppKit/NSTextInputClient/attributedString())

Returns an attributed string representing the receiver’s text storage.

[`attributedSubstring(forProposedRange:actualRange:)`](/documentation/AppKit/NSTextInputClient/attributedSubstring(forProposedRange:actualRange:))

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

[`insertText(_:replacementRange:)`](/documentation/AppKit/NSTextInputClient/insertText(_:replacementRange:))

Inserts the given string into the receiver, replacing the specified content.

### Getting character coordinates

[`characterIndex(for:)`](/documentation/AppKit/NSTextInputClient/characterIndex(for:))

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

[`firstRect(forCharacterRange:actualRange:)`](/documentation/AppKit/NSTextInputClient/firstRect(forCharacterRange:actualRange:))

Returns the first logical boundary rectangle for characters in the given range.

[`baselineDeltaForCharacter(at:)`](/documentation/AppKit/NSTextInputClient/baselineDeltaForCharacter(at:))

Returns the baseline position of a given character relative to the origin of rectangle returned by [`firstRect(forCharacterRange:actualRange:)`](/documentation/AppKit/NSTextInputClient/firstRect(forCharacterRange:actualRange:)).

[`drawsVerticallyForCharacter(at:)`](/documentation/AppKit/NSTextInputClient/drawsVerticallyForCharacter(at:))

Informs the text input management system whether the protocol-conforming client renders the character at the given index vertically.

[`fractionOfDistanceThroughGlyph(for:)`](/documentation/AppKit/NSTextInputClient/fractionOfDistanceThroughGlyph(for:))

Returns the fraction of the distance from the left side of the character to the right side that a given point lies.

### Placing content

[`documentVisibleRect`](/documentation/AppKit/NSTextInputClient/documentVisibleRect)

[`unionRectInVisibleSelectedRange`](/documentation/AppKit/NSTextInputClient/unionRectInVisibleSelectedRange)

[`preferredTextAccessoryPlacement()`](/documentation/AppKit/NSTextInputClient/preferredTextAccessoryPlacement())

[`windowLevel()`](/documentation/AppKit/NSTextInputClient/windowLevel())

Returns the window level of the receiver.

### Binding keystrokes

[`doCommand(by:)`](/documentation/AppKit/NSTextInputClient/doCommand(by:))

Invokes the action specified by the given selector.

### Supporting adaptive images

[`supportsAdaptiveImageGlyph`](/documentation/AppKit/NSTextInputClient/supportsAdaptiveImageGlyph)

A Boolean value that indicates whether the document supports adaptive images in the input.

[`insert(_:replacementRange:)`](/documentation/AppKit/NSTextInputClient/insert(_:replacementRange:))

Inserts an adaptive image into the text at the specifed location.



---

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)