<!--
{
  "availability" : [
    "macOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSControl/addTarget(_:action:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSControl(im)addTarget:action:forControlEvents:"
  },
  "title" : "addTarget(_:action:for:)"
}
-->

# addTarget(_:action:for:)

Registers a target-action pair for the specified control events.

```
func addTarget(_ target: Any?, action: Selector, for controlEvents: NSControl.Events)
```

## Parameters

`target`

The object to receive the action message. Pass `nil` to send the action up the responder chain.

`action`

The selector to invoke on `target` when the specified events occur. This parameter can’t be `nil`. The selector may include the sender, the event, or both as parameters, in that order.

`controlEvents`

A bit mask of [`NSControl.Events`](/documentation/AppKit/NSControl/Events) values specifying which events initiate the action.

## Discussion

You can call this method multiple times to register additional target-action pairs for the same or different events. You can also register multiple targets or multiple actions for the same event. The control holds a weak reference to each registered target.

---

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)