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

# canPerformAction(_:withSender:)

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

```
func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool
```

## Parameters

`action`

A selector that identifies a method associated with a command. For the editing menu, this is one of the editing methods declared by the UIResponderStandardEditActions informal protocol (for example, `copy:`).

`sender`

The object calling this method. For the editing menu commands, this is the shared [`UIApplication`](/documentation/UIKit/UIApplication) object. Depending on the context, you can query the sender for information to help you determine whether a command should be enabled.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the command identified by `action` should be enabled or <doc://com.apple.documentation/documentation/Swift/false> if it should be disabled. Returning <doc://com.apple.documentation/documentation/Swift/true> means that your class can handle the command in the current context.

## Discussion

This default implementation of this method returns <doc://com.apple.documentation/documentation/Swift/true> if the responder class implements the requested action and calls the next responder if it doesn’t. Subclasses may override this method to enable menu commands based on the current state; for example, you would enable the Copy command if there’s a selection or disable the Paste command if the pasteboard didn’t contain data with the correct pasteboard representation type. If no responder in the responder chain returns <doc://com.apple.documentation/documentation/Swift/true>, the menu command is disabled. Note that if your class returns <doc://com.apple.documentation/documentation/Swift/false> for a command, another responder further up the responder chain may still return <doc://com.apple.documentation/documentation/Swift/true>, enabling the command.

This method might be called more than once for the same action but with a different sender each time. You should be prepared for any kind of sender including `nil`.

For information on the editing menu, see the description of the [`UIMenuController`](/documentation/UIKit/UIMenuController) class.

---

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)