Contents

UICommand

A menu element that performs its action in a selector.

Declaration

@MainActor class UICommand

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

Getting command alternatives

Associating data

Initializers

See Also

Menu elements and keyboard shortcuts