A menu element that performs its action in a selector.


class UICommand : UIMenuElement


Create a UICommand object when you want a menu element that performs its action in a selector available in the responder chain.

// 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)


Getting Information About the Command

var title: String

The command's title.

var image: UIImage?

The command's image.

var action: Selector

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

var discoverabilityTitle: String?

An elaborated title that explains the purpose of the command.

var attributes: UIMenuElement.Attributes

The attributes indicating the style of the command.

var state: UIMenuElement.State

The state of the command.

Getting Command Alternatives

var alternates: [UICommandAlternate]

An array of alternative actions to take for the command.

class UICommandAlternate

An object representing an alternative action for a command.

Associating Data

var propertyList: Any?

An object that contains data to associate with the command.

let UICommandTagShare: String

A value that identifies a command as a Share menu.


Inherits From

Conforms To

See Also

Menu Elements and Keyboard Shortcuts

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.

class UIMenuElement

An object representing a menu, action, or command.

class UIAction

A menu element that performs its action in a closure.

class UIKeyCommand

An object that specifies a key press performed on a hardware keyboard and the resulting action.

struct UIMenuElement.Attributes

Attributes that determine the style of the menu element.

enum UIMenuElement.State

Constants that indicate the state of an action- or command-based menu element.