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

# textView(_:doCommandBy:)

Sent to allow the delegate to perform the command for the text view.

```
@MainActor optional func textView(_ textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool
```

## Parameters

`textView`

The text view sending the message. This is the first text view in a series shared by a layout manager.

`commandSelector`

The selector.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> indicates that the delegate handled the command and the text view will not attempt to perform it; <doc://com.apple.documentation/documentation/Swift/false> indicates that the delegate did not handle the command the text view will attempt to perform it.

## Discussion

This method is invoked by `NSTextView`’s `doCommand(by:)` method.

---

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)