---
title: "addTarget(_:action:for:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nscontrol/addtarget(_:action:for:)"
---

# addTarget(_:action:for:)

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

## Declaration

```swift
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 doc://com.apple.appkit/documentation/AppKit/NSControl/Events values specifying which events initiate the action.

## Discussion

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.

## See Also

### Handling Control Events

- [NSControl.Events](appkit/nscontrol/events.md)
- [removeTarget(_:action:for:)](appkit/nscontrol/removetarget(_:action:for:).md)
