<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIControl/addTarget(_:action:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIControl(im)addTarget:action:forControlEvents:"
  },
  "title" : "addTarget(_:action:for:)"
}
-->

# addTarget(_:action:for:)

Associates a target object and action method with the control.

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

## Parameters

`target`

The target object—that is, the object whose `action` method is called. If you specify `nil`, UIKit searches the responder chain for an object that responds to the specified action message and delivers the message to that object.

`action`

A selector identifying the action method to be called. You may specify a selector whose signature matches any of the signatures in the code example in [`UIControl`](/documentation/UIKit/UIControl). This parameter must not be `nil`.

`controlEvents`

A bitmask specifying the control-specific events for which the action method is called. Always specify at least one constant. For a list of possible constants, see [`UIControl.Event`](/documentation/UIKit/UIControl/Event).

## Discussion

You may call this method multiple times to configure multiple targets and actions for the control. It is also safe to call this method multiple times with the same values for the `target` and `action` parameters. The control maintains a list of its attached targets and actions along with the events each supports.

The control does not retain the object in the `target` parameter. It is your responsibility to maintain a strong reference to the target object while it is attached to a control.

Specifying a value of `0` for the `controlEvents` parameter does not prevent events from being sent to a previously registered `target` and `action` method. To stop the delivery of events, always call the [`removeTarget(_:action:for:)`](/documentation/UIKit/UIControl/removeTarget(_:action:for:)) 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)