menu(_:update:at:shouldCancel:)
Invoked to let the delegate update a menu item before it is displayed.
Declaration
@MainActor optional func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> BoolParameters
- menu:
The menu object that owns
item. - item:
The menu-item object that may be updated.
- index:
The integer index of the menu item.
- shouldCancel:
Set to True if, due to some user action, the menu no longer needs to be displayed before all the menu items have been updated. You can ignore this flag, return True, and continue; or you can save your work (to save time the next time your delegate is called) and return False to stop the updating.
Return Value
true to continue the process. If you return false, your menu(_:update:at:shouldCancel:) is not called again. In that case, it’s your responsibility to trim any extra items from the menu.
Discussion
If your numberOfItems(in:) delegate method returns a positive value, then your menu(_:update:at:shouldCancel:) method is called for each item in the menu. You can then update the menu title, image, and so forth for each menu item.