<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/NSObject-swift.class/didCommand(by:client:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Objective-C Runtime",
      "ObjectiveC"
    ],
    "preciseIdentifier" : "c:objc(cs)NSObject(im)didCommandBySelector:client:"
  },
  "title" : "didCommand(by:client:)"
}
-->

# didCommand(by:client:)

Processes a command  generated by user action such as typing certain keys or pressing the mouse button.

```
func didCommand(by aSelector: Selector!, client sender: Any!) -> Bool
```

## Parameters

`aSelector`

The action associated with the key down event. The selector can be an action specified in the input method  dictionary of keys and actions (that is, an action specific to the input method) or one of the `NSResponder` action methods such as `insertNewline:` or `deleteBackward:`. By definition such action methods do not return a value.

`sender`

The client object sending the key down event.

## Return Value

[`YES`](/documentation/ObjectiveC/YES) if the command is handled; [`NO`](/documentation/ObjectiveC/NO) if the command is not handled. If not handled, the event passes to the client.

## Discussion

This method is called when the system binds a key down event to an action method. If you implement this method you should test if it is appropriate to call the action method before actually calling it, because calling the action method implies that you agree to handle the command. Suppose you have implemented a version of `insertNewline:`  that terminates the conversion session and sends the fully converted text to the client. However, if you conversion buffer is empty, you want the application to receive the return key that triggered the call to `insertNewline:`. In that case, when `didCommandBySelector:client:` is called you should test your buffer before calling your implementation of `insertNewline:`. If the buffer is empty, return [`NO`](/documentation/ObjectiveC/NO) to indicate that the return key should be passed on to the application. If the buffer is not empty, call `insertNewline:` and then return [`YES`](/documentation/ObjectiveC/YES) as the result of `didCommandBySelector:client:`.

## See Also

[`-  inputText:client:`](/documentation/ObjectiveC/NSObject-swift.class/inputText(_:client:))

Handles key down events that do not map to an action 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)