target(forAction:to:from:)
Searches for an object that can receive the message specified by the given selector.
Declaration
func target(forAction action: Selector, to target: Any?, from sender: Any?) -> Any?Parameters
- action:
The desired action message. May be
nil, in which case this method will returnnil. - target:
The target object to check. Specify
nilif you want to search the responder chain starting with the current first responder. - sender:
The potential sender for the action message.
Return Value
The object that can accept the specified action message or nil if no target object can receive the message from the specified sender. Returns nil if anAction is nil.
Discussion
The system looks for an object that implements a method matching anAction.
If aTarget is specified, the system verifies that it’s a valid target for the provided action and sender, returning aTarget if valid, nil otherwise.
If the provided target is nil, the search begins with the first responder of the key window. The system follows the responder object looking for targets. If no object capable of handling the message is found in the responder chain, the system returns nil.