Class

UIAction

A menu element that performs its action in a block.

Declaration

@interface UIAction : UIMenuElement

Overview

Create a UIAction object when you want a menu element that performs its action in a closure.

Listing 1

Adds an action-based menu to the File menu

// Create a closure-based action to use as a menu element.
let refreshAction = UIAction(title: "Refresh") { (action) in
    print("Refresh the data.")
}

// 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: [refreshAction])

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

Topics

Creating an Action

UIActionIdentifier

A type that represents an action identifier.

UIActionHandler

A type that defines the block for an action handler.

Getting Information About the Action

title

The action's title.

image

The action's image.

identifier

The unique identifier for the action.

discoverabilityTitle

An elaborated title that explains the purpose of the action.

attributes

The attributes indicating the style of the action.

state

The state of the action.

Relationships

Inherits From

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 Catalyst app.

UIMenuElement

An object representing a menu, action, or command.

UICommand

A menu element that performs its action in a selector.

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.

UIMenuElementState

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