A menu element that performs its action in a closure.


class UIAction : UIMenuElement


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)


Getting Information About the Action

var title: String

The action's title.

var image: UIImage?

The action's image.

var identifier: UIAction.Identifier

The unique identifier for the action.

var discoverabilityTitle: String?

An elaborated title that explains the purpose of the action.

var attributes: UIMenuElement.Attributes

The attributes indicating the style of the action.

var state: UIMenuElement.State

The state of the action.


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 UICommand

A menu element that performs its action in a selector.

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.