Contents

system

The menu system that the menu builder modifies.

Declaration

var system: UIMenuSystem { get }

Discussion

Always check the system property to determine which menu system the builder is modifying before you add and remove menus. For example, when you want to modify the main menu bar, check system for main.

override func buildMenu(with builder: UIMenuBuilder) {
    super.buildMenu(with: builder)
    
    // Ensure that the builder is modifying the menu bar system.
    guard builder.system == UIMenuSystem.main else { return }
    
    let refreshCommand = UICommand(title: "Refresh", action: #selector(refreshData(_:)))
    let refreshMenu = UIMenu(title: "", options: .displayInline, children: [refreshCommand])

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

See Also

Getting menu systems and elements