<!--
{
  "availability" : [
    "macOS: 10.0.0 - 10.11.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextView/insertText(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextView(im)insertText:"
  },
  "title" : "insertText(_:)"
}
-->

# insertText(_:)

Inserts `aString` into the receiver’s text at the insertion point if there is one, otherwise replacing the selection.

```
func insertText(_ insertString: Any)
```

## Parameters

`insertString`

The string to insert. `aString` can be either an <doc://com.apple.documentation/documentation/Foundation/NSString> object or an <doc://com.apple.documentation/documentation/Foundation/NSAttributedString> object.

## Discussion

The inserted text is assigned the current typing attributes.

This method is the means by which text typed by the user enters an NSTextView. See the [`NSInputManager`](/documentation/AppKit/NSInputManager) class and [`NSTextInput`](/documentation/AppKit/NSTextInput) protocol specifications for more information.

This method is the entry point for inserting text typed by the user and is generally not suitable for other purposes. Programmatic modification of the text is best done by operating on the text storage directly. Because this method pertains to the actions of the user, the text view must be editable for the insertion to work.

## See Also

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

The receiver’s typing attributes.



---

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)