<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UICommand",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UICommand"
  },
  "title" : "UICommand"
}
-->

# UICommand

A menu element that performs its action in a selector.

```
@MainActor class UICommand
```

## Overview

Create a [`UICommand`](/documentation/UIKit/UICommand) object when you want a menu element that performs its action in a selector available in the responder chain.

```swift
// Create a selector-based action to use as a menu element.
let refreshCommand = UICommand(title: "Refresh", action: #selector(refreshData(_:)))

// Use the .displayInline option to avoid displaying the menu as a submenu,
// and to separate it from the other menu elements using a line separator.
let refreshMenuItem = UIMenu(title: "", options: .displayInline, children: [refreshCommand])

// Insert the menu into the File menu before the Close menu.
builder.insertSibling(refreshMenuItem, beforeMenu: .close)
```

## Topics

### Creating a command

[`convenience init(title: String, subtitle: String?, image: UIImage?, action: Selector, propertyList: Any?, alternates: [UICommandAlternate], discoverabilityTitle: String?, attributes: UIMenuElement.Attributes, state: UIMenuElement.State)`](/documentation/UIKit/UICommand/init(title:subtitle:image:action:propertyList:alternates:discoverabilityTitle:attributes:state:))

Creates a command with the specified title, subtitle, image, action, property list, alternative commands, discoverability title, attributes, and state.

[`convenience init(title: String, image: UIImage?, action: Selector, propertyList: Any?, alternates: [UICommandAlternate], discoverabilityTitle: String?, attributes: UIMenuElement.Attributes, state: UIMenuElement.State)`](/documentation/UIKit/UICommand/init(title:image:action:propertyList:alternates:discoverabilityTitle:attributes:state:))

Creates a command with the specified title, image, action, property list, alternative commands, discoverability title, attributes, and state.

[`+ (instancetype) commandWithTitle:(NSString *) title image:(UIImage *) image action:(SEL) action propertyList:(id) propertyList;`](/documentation/UIKit/UICommand/commandWithTitle:image:action:propertyList:)

Creates a command with the specified title, image, action, and property list.

[`+ (instancetype) commandWithTitle:(NSString *) title image:(UIImage *) image action:(SEL) action propertyList:(id) propertyList alternates:(NSArray<UICommandAlternate *> *) alternates;`](/documentation/UIKit/UICommand/commandWithTitle:image:action:propertyList:alternates:)

Creates a command with the specified title, image, action, property list, and alternative commands.

[`init?(coder: NSCoder)`](/documentation/UIKit/UICommand/init(coder:))

Creates a command from data in an unarchiver.

[Adding menus and shortcuts to the menu bar and user interface](/documentation/UIKit/adding-menus-and-shortcuts-to-the-menu-bar-and-user-interface)

Provide quick access to useful actions by adding menus and keyboard shortcuts to your Mac app built with Mac Catalyst.

### Getting information about the command

[`var title: String`](/documentation/UIKit/UICommand/title)

The command’s title.

[`var image: UIImage?`](/documentation/UIKit/UICommand/image)

The command’s image.

[`var action: Selector`](/documentation/UIKit/UICommand/action)

The selector identifying the action method called after the user selects the command.

[`var discoverabilityTitle: String?`](/documentation/UIKit/UICommand/discoverabilityTitle)

An elaborated title that explains the purpose of the command.

[`var attributes: UIMenuElement.Attributes`](/documentation/UIKit/UICommand/attributes)

The attributes indicating the style of the command.

[`var state: UIMenuElement.State`](/documentation/UIKit/UICommand/state)

The state of the command.

### Getting command alternatives

[`var alternates: [UICommandAlternate]`](/documentation/UIKit/UICommand/alternates)

An array of alternative actions to take for the command.

[`class UICommandAlternate`](/documentation/UIKit/UICommandAlternate)

An object representing an alternative action for a command.

### Associating data

[`var propertyList: Any?`](/documentation/UIKit/UICommand/propertyList)

An object that contains data to associate with the command.

[`let UICommandTagShare: String`](/documentation/UIKit/UICommandTagShare)

A value that identifies a command as a Share menu.

### Initializers

[`convenience init(title: String, subtitle: String?, image: UIImage?, selectedImage: UIImage?, action: Selector, propertyList: Any?, alternates: [UICommandAlternate], discoverabilityTitle: String?, attributes: UIMenuElement.Attributes, state: UIMenuElement.State)`](/documentation/UIKit/UICommand/init(title:subtitle:image:selectedImage:action:propertyList:alternates:discoverabilityTitle:attributes:state:))

### Initializers

[`convenience init(title: String, subtitle: String?, image: UIImage?, selectedImage: UIImage?, preferredImageVisibility: UIMenuElement.ImageVisibility, action: Selector, propertyList: Any?, alternates: [UICommandAlternate], discoverabilityTitle: String?, attributes: UIMenuElement.Attributes, state: UIMenuElement.State)`](/documentation/UIKit/UICommand/init(title:subtitle:image:selectedImage:preferredImageVisibility:action:propertyList:alternates:discoverabilityTitle:attributes:state:))

## Relationships

### Conforms To

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`UIMenuLeaf`](/documentation/UIKit/UIMenuLeaf)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`UIAccessibilityIdentification`](/documentation/UIKit/UIAccessibilityIdentification)

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Inherits From

[`UIMenuElement`](/documentation/UIKit/UIMenuElement)

### Inherited By

[`UIKeyCommand`](/documentation/UIKit/UIKeyCommand)

---

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)