Instance Method

target(forAction:withSender:)

Returns the target object that responds to an action.

Declaration

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 UIApplication object. Depending on the context, you can query the sender for information to help you determine the target of the command.

Return Value

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

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

func validate(UICommand)

Asks the receiving responder to validate the command.

func canPerformAction(Selector, withSender: Any?) -> Bool

Requests the receiving responder to enable or disable the specified command in the user interface.