---
title: "target(forAction:withSender:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiresponder/target(foraction:withsender:)"
---

# target(forAction:withSender:)

Returns the target object that responds to an action.

## Declaration

```swift
func target(forAction action: Selector, withSender sender: Any?) -> Any?
```

## Parameters

- `action`: A selector that identifies a method associated with a command.
- `sender`: The object calling this method. For the editing menu commands, this is the shared doc://com.apple.uikit/documentation/UIKit/UIApplication object. Depending on the context, you can query the sender for information to help you determine the target of the command.

## Return Value

Return Value The object whose action method is invoked to execute the command.

## Discussion

Discussion This method is called whenever an action needs to be invoked by the object. The default implementation calls the canPerformAction(_:withSender:) method to determine whether it can invoke the action. If the object can invoke the action, it returns itself, otherwise it passes the request up the responder chain. Your app should override this method if it wants to override how a target is selected.

## See Also

### Building and validating commands

- [buildMenu(with:)](uikit/uiresponder/buildmenu(with:).md)
- [validate(_:)](uikit/uiresponder/validate(_:).md)
- [canPerformAction(_:withSender:)](uikit/uiresponder/canperformaction(_:withsender:).md)
