Class

UICommand

A menu element that performs its action in a selector.

Declaration

@interface UICommand : UIMenuElement

Overview

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)

Topics

Creating a Command

Getting Information About the Command

title

The command's title.

image

The command's image.

action

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

discoverabilityTitle

An elaborated title that explains the purpose of the command.

attributes

The attributes indicating the style of the command.

state

The state of the command.

Getting Command Alternatives

alternates

An array of alternative actions to take for the command.

UICommandAlternate

An object representing an alternative action for a command.

Associating Data

propertyList

An object that contains data to associate with the command.

UICommandTagShare

A value that identifies a command as a Share menu.

Relationships

Inherits From

See Also

Menu Elements and Keyboard Shortcuts

UIMenuElement

An object representing a menu, action, or command.

Beta
UIAction

A menu element that performs its action in a block.

Beta
UIKeyCommand

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

UIMenuElementAttributes

Attributes that determine the style of the menu element.

Beta
UIMenuElementState

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

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software