blog icon indicating copy to clipboard operation
blog copied to clipboard

How to enable NSMenuItem in AppKit

Open onmyway133 opened this issue 5 years ago • 1 comments

Need to set target

let item = NSMenuItem(
    title: title,
    action: #selector(onMenuItemClicked(_:)),
    keyEquivalent: ""
)

item.target = self

Sometimes, need to check autoenablesItems

Indicates whether the menu automatically enables and disables its menu items.

This property contains a Boolean value, indicating whether the menu automatically enables and disables its menu items. If set to true, menu items of the menu are automatically enabled and disabled according to rules computed by the NSMenuValidation informal protocol. By default, NSMenu objects autoenable their menu items.

onmyway133 avatar Sep 25 '19 10:09 onmyway133