Contents

UIAction

A menu element that performs its action in a closure.

Declaration

@MainActor class UIAction

Overview

Create a UIAction object when you want a menu element that performs its action in a closure. The following example 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

Getting information about the action

Initializers

See Also

Menu elements and keyboard shortcuts