An interface for adding and removing menus from a menu system.


protocol UIMenuBuilder


You don't create a menu builder object. Instead, you override buildMenu(with:) in your app delegate or view controller to receive a builder object. Where you override this method determines the system that the builder updates. To add and remove menus from the menu bar using the main menu system, override buildMenu(with:) in your app delegate. To build a context menu using the context system, override the method in your view controller.

To see an example of how to use a menu builder object, see Adding Menus and Shortcuts to the Menu Bar and User Interface.


Getting Menu Systems and Elements

var system: UIMenuSystem

The menu system that the menu builder modifies.


func menu(for: UIMenu.Identifier) -> UIMenu?

Gets the menu for the specified menu identifier.


func action(for: UIAction.Identifier) -> UIAction?

Gets the action for the specified action identifier.


func command(for: Selector, propertyList: Any?) -> UICommand?

Gets the command for the specified selector and property list.

Inserting Child Menus

func insertChild(UIMenu, atStartOfMenu: UIMenu.Identifier)

Adds a child menu as the first element of the specified parent menu.


func insertChild(UIMenu, atEndOfMenu: UIMenu.Identifier)

Adds a child menu as the last element of the specified parent menu.


Inserting Sibling Menus

func insertSibling(UIMenu, beforeMenu: UIMenu.Identifier)

Inserts a sibling menu before the specified menu.


func insertSibling(UIMenu, afterMenu: UIMenu.Identifier)

Inserts a sibling menu after the specified menu.


Replacing Menus and Child Menu Elements

func replace(menu: UIMenu.Identifier, with: UIMenu)

Replaces the specified menu with a new menu.


func replaceChildren(ofMenu: UIMenu.Identifier, from: ([UIMenuElement]) -> [UIMenuElement])

Replaces the menu elements in a menu with the elements returned by the specified handler block.


Removing a Menu

func remove(menu: UIMenu.Identifier)

Removes a menu from the menu system.


See Also

App Menus

class UIMenu

A container for grouping related menu elements in an app menu or contextual menu.

class UIMenuSystem

An object representing a main or contextual menu system.