Mac Developer Library

Developer

AppKit Framework Reference NSMenu Class Reference

Options
Deployment Target:

On This Page
Language:

NSMenu

The NSMenu class defines an object that manages an application’s menus.

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns a Boolean value that indicates whether the menu bar is visible.

    Declaration

    Swift

    class func menuBarVisible() -> Bool

    Objective-C

    + (BOOL)menuBarVisible

    Return Value

    YEStrue if the menu bar is visible, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.2 and later.

  • Sets whether the menu bar is visible and selectable by the user.

    Declaration

    Swift

    class func setMenuBarVisible(_ visible: Bool)

    Objective-C

    + (void)setMenuBarVisible:(BOOL)visible

    Parameters

    visible

    YEStrue if menu bar is to be visible, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.2 and later.

  • Returns the menu bar height for the current application’s main menu.

    Declaration

    Swift

    var menuBarHeight: CGFloat { get }

    Objective-C

    @property(readonly) CGFloat menuBarHeight

    Return Value

    The receiver's main menu bar height or 0.0 if the receiver is some other menu.

    Discussion

    This method supersedes the menuBarHeight class method of the NSMenuView class.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Initializes and returns a menu having the specified title and with autoenabling of menu items turned on.

    Declaration

    Swift

    init(title aTitle: String)

    Objective-C

    - (instancetype)initWithTitle:(NSString *)aTitle

    Parameters

    aTitle

    The title to assign to the receiver.

    Return Value

    The initialized NSMenu object or nil if the object could not be initialized.

    Special Considerations

    This method is the designated initializer for the class.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Inserts a menu item into the receiver at a specific location.

    Declaration

    Swift

    func insertItem(_ newItem: NSMenuItem, atIndex index: Int)

    Objective-C

    - (void)insertItem:(NSMenuItem *)newItem atIndex:(NSInteger)index

    Parameters

    newItem

    An object conforming to the NSMenuItem protocol that represents a menu item.

    index

    An integer index identifying the location of the menu item in the menu.

    Discussion

    This method posts an NSMenuDidAddItemNotification, allowing interested observers to update as appropriate. This method is a primitive method. All item-addition methods end up calling this method, so this is where you should implement custom behavior on adding new items to a menu in a custom subclass. If the menu item already exists in another menu, it is not inserted and the method raises an exception of type NSInternalInconsistencyException.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates and adds a menu item at a specified location in the receiver.

    Declaration

    Swift

    func insertItemWithTitle(_ aString: String, action aSelector: Selector, keyEquivalent keyEquiv: String, atIndex index: Int) -> NSMenuItem?

    Objective-C

    - (NSMenuItem *)insertItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv atIndex:(NSInteger)index

    Parameters

    aString

    A string to be made the title of the menu item.

    aSelector

    The action-message selector to assign to the menu item.

    keyEquiv

    A string identifying the key to use as a key equivalent for the menu item. If you do not want the menu item to have a key equivalent, keyEquiv should be an empty string (@"") and not nil.

    index

    An integer index identifying the location of the menu item in the menu.

    Return Value

    The new menu item (an object conforming to the NSMenuItem protocol) or nil if the item could not be created

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Adds a menu item to the end of the receiver.

    Declaration

    Swift

    func addItem(_ newItem: NSMenuItem)

    Objective-C

    - (void)addItem:(NSMenuItem *)newItem

    Parameters

    newItem

    The menu item (an object conforming to the NSMenuItem protocol) to add to the menu.

    Discussion

    This method invokes insertItem:atIndex:. Thus, the receiver does not accept the menu item if it already belongs to another menu. After adding the menu item, the receiver updates itself.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Creates a new menu item and adds it to the end of the receiver.

    Declaration

    Swift

    func addItemWithTitle(_ aString: String, action aSelector: Selector, keyEquivalent keyEquiv: String) -> NSMenuItem?

    Objective-C

    - (NSMenuItem *)addItemWithTitle:(NSString *)aString action:(SEL)aSelector keyEquivalent:(NSString *)keyEquiv

    Parameters

    aString

    A string to be made the title of the menu item.

    aSelector

    The action-message selector to assign to the menu item.

    keyEquiv

    A string identifying the key to use as a key equivalent for the menu item. If you do not want the menu item to have a key equivalent, keyEquiv should be an empty string (@"") and not nil.

    Return Value

    The created menu item (an object conforming to the NSMenuItem protocol) or nil if the object couldn't be created.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Removes a menu item from the receiver.

    Declaration

    Swift

    func removeItem(_ anItem: NSMenuItem)

    Objective-C

    - (void)removeItem:(NSMenuItem *)anItem

    Parameters

    anItem

    The menu item to remove.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Removes the menu item at a specified location in the receiver.

    Declaration

    Swift

    func removeItemAtIndex(_ index: Int)

    Objective-C

    - (void)removeItemAtIndex:(NSInteger)index

    Parameters

    index

    An integer index identifying the menu item.

    Discussion

    After it removes the menu item, this method posts an NSMenuDidRemoveItemNotification.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Invoked when a menu item is modified visually (for example, its title changes).

    Declaration

    Swift

    func itemChanged(_ anObject: NSMenuItem)

    Objective-C

    - (void)itemChanged:(NSMenuItem *)anObject

    Parameters

    anObject

    The menu item that has visually changed.

    Discussion

    This method is not called for changes involving the menu item's action, target, represented object, or tag. Posts an NSMenuDidChangeItemNotification.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Removes all the menu items in the receiver.

    Declaration

    Swift

    func removeAllItems()

    Objective-C

    - (void)removeAllItems

    Discussion

    This method is more efficient than removing menu items individually.

    Unlike the other remove methods, this method does not post NSMenuDidChangeItemNotification notifications.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns the first menu item in the receiver with the specified tag.

    Declaration

    Swift

    func itemWithTag(_ aTag: Int) -> NSMenuItem?

    Objective-C

    - (NSMenuItem *)itemWithTag:(NSInteger)aTag

    Parameters

    aTag

    A numeric tag associated with a menu item.

    Return Value

    The found menu item (an object conforming to the NSMenuItem protocol) or nil if the object couldn't be found.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the first menu item in the receiver with a specified title.

    Declaration

    Swift

    func itemWithTitle(_ aString: String) -> NSMenuItem?

    Objective-C

    - (NSMenuItem *)itemWithTitle:(NSString *)aString

    Parameters

    aString

    The title of a menu item.

    Return Value

    The found menu item (an object conforming to the NSMenuItem protocol) or nil if the object couldn't be found.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the menu item at a specific location of the receiver.

    Declaration

    Swift

    func itemAtIndex(_ index: Int) -> NSMenuItem?

    Objective-C

    - (NSMenuItem *)itemAtIndex:(NSInteger)index

    Parameters

    index

    An integer index locating a menu item in a menu.

    Return Value

    The found menu item (an object conforming to the NSMenuItem protocol) or nil if the object couldn't be found.

    Discussion

    This method raises an exception if index is out of bounds.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the number of menu items in the receiver, including separator items.

    Declaration

    Swift

    var numberOfItems: Int { get }

    Objective-C

    @property(readonly) NSInteger numberOfItems

    Return Value

    The number of menu items in the receiver, including separator items.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – itemArray

  • Returns an array containing the receiver’s menu items.

    Declaration

    Swift

    var itemArray: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *itemArray

    Return Value

    An array containing the receiver’s menu items.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Assigns a menu to be a submenu of the receiver controlled by a given menu item.

    Declaration

    Swift

    func setSubmenu(_ aMenu: NSMenu?, forItem anItem: NSMenuItem)

    Objective-C

    - (void)setSubmenu:(NSMenu *)aMenu forItem:(NSMenuItem *)anItem

    Parameters

    aMenu

    A menu object that is to be a submenu of the receiver.

    anItem

    A menu item (that is, an object conforming to the NSMenuItem protocol) that controls aMenu. The method sets the action of anItem to submenuAction:.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • The action method assigned to menu items that open submenus.

    Declaration

    Swift

    func submenuAction(_ sender: AnyObject?)

    Objective-C

    - (void)submenuAction:(id)sender

    Discussion

    You may override this method to implement different behavior. Never invoke this method directly.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the menu currently attached to the receiver.

    Declaration

    Objective-C

    - (NSMenu *)attachedMenu

    Return Value

    The menu currently attached to the receiver or nil if there’s no such object.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

    See Also

    – isAttached

  • isAttached - isAttached (OS X v10.2)

    Returns a Boolean value that indicates whether the receiver is currently attached to another menu.

    Declaration

    Objective-C

    - (BOOL)isAttached

    Return Value

    YEStrue if the receiver is currently attached to another menu, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Returns the location in screen coordinates where the given submenu is displayed when opened as a submenu of the receiver.

    Declaration

    Objective-C

    - (NSPoint)locationForSubmenu:(NSMenu *)aSubmenu

    Parameters

    aSubmenu

    A menu object that is a submenu of the receiver.

    Return Value

    An NSPoint structure describing the location or (0.0, 0.0) if the submenu does not exist in the receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Returns the receiver’s supermenu.

    Declaration

    Swift

    unowned(unsafe) var supermenu: NSMenu?

    Objective-C

    @property(assign) NSMenu *supermenu

    Return Value

    The receiver’s supermenu or nil if it has none.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s supermenu.

    Declaration

    Swift

    unowned(unsafe) var supermenu: NSMenu?

    Objective-C

    @property(assign) NSMenu *supermenu

    Parameters

    supermenu

    A menu object to set as the supermenu of the receiver.

    Discussion

    You should never invoke this method directly; it is public so subclassers can add behavior to the default implementation. Subclassers should call the superclass’s method as part of their implementation.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – supermenu

  • isTornOff - isTornOff Available in OS X v10.0 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver is offscreen or attached to another menu (or if it’s the main menu).

    Declaration

    Objective-C

    - (BOOL)isTornOff

    Return Value

    NOfalse if the receiver is offscreen or attached to another menu (or if it’s the main menu), otherwise YEStrue.

    Special Considerations

    On OS X v10.6 and later this method has no effect.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 through OS X v10.9.

  • Returns a Boolean value that indicates whether the receiver automatically enables and disables its menu items.

    Declaration

    Swift

    var autoenablesItems: Bool

    Objective-C

    @property BOOL autoenablesItems

    Return Value

    YEStrue if the receiver automatically enables and disables its menu items (based on the NSMenuValidation informal protocol), otherwise NOfalse.

    Discussion

    By default, NSMenu objects autoenable their menu items. See the protocol specification for more information.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Controls whether the receiver automatically enables and disables its menu items based on delegates implementing the NSMenuValidation informal protocol.

    Declaration

    Swift

    var autoenablesItems: Bool

    Objective-C

    @property BOOL autoenablesItems

    Parameters

    flag

    If flag is YEStrue, menu items are automatically enabled and disabled. If flag is NOfalse, menu items are not automatically enabled or disabled.

    Discussion

    See the NSMenuValidation protocol specification for more information.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Enables or disables the receiver’s menu items based on the NSMenuValidation informal protocol and sizes the menu to fit its current menu items if necessary.

    Declaration

    Swift

    func update()

    Objective-C

    - (void)update

    Discussion

    See the NSMenuValidation protocol specification for more information.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the font used to display the menu and its submenus.

    Declaration

    Swift

    var font: NSFont!

    Objective-C

    @property(strong) NSFont *font

    Return Value

    The font object used for displaying the menu.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

    See Also

    – setFont:

  • Sets the font used to display the menu and its submenus.

    Declaration

    Swift

    var font: NSFont!

    Objective-C

    @property(strong) NSFont *font

    Parameters

    font

    The font object to use.

    Discussion

    This font will be used to display the menu and any submenus that have not had their font set explicitly.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

    See Also

    – font

  • Causes the application to send the action message of a specified menu item to its target.

    Declaration

    Swift

    func performActionForItemAtIndex(_ index: Int)

    Objective-C

    - (void)performActionForItemAtIndex:(NSInteger)index

    Parameters

    index

    The integer index of a menu item.

    Discussion

    If a target is not specified, the message is sent to the first responder. As a side effect, this method posts NSMenuWillSendActionNotification and NSMenuDidSendActionNotification.

    In OS X v10.6 and later the performActionForItemAtIndex: no longer triggers menu validation. This is because validation is typically done during menu tracking or key equivalent matching, so the subsequent performActionForItemAtIndex: validation was redundant. To trigger validation explicitly, use invoke the update method.

    In OS X v10.6 performActionForItemAtIndex:, when called, now triggers highlighting in the menu bar. It also sends out appropriate accessibility notifications indicating the item was selected.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s title.

    Declaration

    Swift

    var title: String

    Objective-C

    @property(copy) NSString *title

    Parameters

    aString

    A string to assign as the new title of the receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – title

  • Returns the receiver’s title.

    Declaration

    Swift

    var title: String

    Objective-C

    @property(copy) NSString *title

    Return Value

    The receiver’s title.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setTitle:

  • Returns the minimum width of the menu.

    Declaration

    Swift

    var minimumWidth: CGFloat

    Objective-C

    @property CGFloat minimumWidth

    Return Value

    The minimum width of the menu in screen coordinates.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Set the minimum width of the menu.

    Declaration

    Swift

    var minimumWidth: CGFloat

    Objective-C

    @property CGFloat minimumWidth

    Parameters

    width

    The minimum width of the menu in screen coordinates.

    Discussion

    The menu will not draw smaller than its minimum width, but may draw larger if it needs more space. The default value is 0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns the size of the menu.

    Declaration

    Swift

    var size: NSSize { get }

    Objective-C

    @property(readonly) NSSize size

    Return Value

    The size of the menu in screen coordinates.

    Discussion

    The menu may draw at a smaller size when shown, depending on its positioning and display configuration.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • sizeToFit - sizeToFit (OS X v10.2)

    Resizes the receiver to exactly fit its items.

    Declaration

    Objective-C

    - (void)sizeToFit

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Returns the available properties for the menu.

    Declaration

    Swift

    var propertiesToUpdate: NSMenuProperties { get }

    Objective-C

    @property(readonly) NSMenuProperties propertiesToUpdate

    Return Value

    A bitwise-C OR of the values in the NSMenuProperties that are applicable to this menu.

    Discussion

    The propertiesToUpdate method may be called on the menu from specific callbacks to determine which properties the have been defined, and whether or not they are relevant to the changes you need to make. It is intended to allow more efficient updating of the menu in certain circumstances.

    For example, if NSMenuPropertyItemImage is not set, your delegate does not need to update the images of the menu items, because the images are not needed (for example, during key equivalent matching). If the NSMenuPropertyItemImage bit is 0, you can avoid updating the menu's images, which may improve performance if computing the images is expensive.

    You only have to update a property if it may have changed since you last set it, even if the corresponding bit is 1. For example, if the title of a menu item never changes, you only have to set it once.

    You may call this from the menu delegate methods menuNeedsUpdate:, or the menu validation methods -validateMenuItem: or validateUserInterfaceItem:. Calling this at other times will raise an exception.

    If a menu property does not have a corresponding bit, you should ensure it is always set properly after the callback returns.

    Calling this is optional; it is always acceptable to fully update all properties of the menu.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns a Boolean value that indicates whether messages are sent to the application’s windows upon each change to the receiver.

    Declaration

    Swift

    var menuChangedMessagesEnabled: Bool

    Objective-C

    @property BOOL menuChangedMessagesEnabled

    Return Value

    YEStrue if messages are sent to the application’s windows upon each change to the receiver, otherwise NOfalse.

    Special Considerations

    On OS X v10.6 and later this method has no effect. This method may be deprecated in a future release.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Controls whether the receiver sends messages to the application’s windows upon each menu change.

    Declaration

    Swift

    var menuChangedMessagesEnabled: Bool

    Objective-C

    @property BOOL menuChangedMessagesEnabled

    Parameters

    flag

    YEStrue if the receiver should send a message at each menu change, NOfalse otherwise.

    Discussion

    To avoid the “flickering” effect of many successive menu changes, invoke this method with flag set to NOfalse, make changes to the menu, and invoke the method again with flag set to YEStrue. This approach has the effect of batching changes and applying them all at once.

    Special Considerations

    On OS X v10.6 and later this method has no effect. This method may be deprecated in a future release.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns whether the popup menu allows appending of contextual menu plugin items.

    Declaration

    Swift

    var allowsContextMenuPlugIns: Bool

    Objective-C

    @property BOOL allowsContextMenuPlugIns

    Return Value

    YEStrue if the popup menu allows appending of contextual menu plugin items, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Sets whether the popup menu allows appending of contextual menu plugin items.

    Declaration

    Swift

    var allowsContextMenuPlugIns: Bool

    Objective-C

    @property BOOL allowsContextMenuPlugIns

    Parameters

    allows

    YEStrue if the popup menu should allow context menu plugin items to be appending, otherwise NOfalse.

    Discussion

    Contextual menu plugins are system-wide services provided by other applications. For example, a contextual menu plugin might provide an “Open URL...” service. By enabling context menu plugins your application’s contextual menu will display the appropriate items for the currently selected data type.

    See Services Implementation Guide for more information on contextual menu plugins.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Displays a contextual menu over a view for an event.

    Declaration

    Swift

    class func popUpContextMenu(_ menu: NSMenu, withEvent event: NSEvent, forView view: NSView)

    Objective-C

    + (void)popUpContextMenu:(NSMenu *)menu withEvent:(NSEvent *)event forView:(NSView *)view

    Parameters

    menu

    The menu object to use for the contextual menu.

    event

    An NSEvent object representing the event.

    view

    The view object over which to display the contextual menu.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Displays a contextual menu over a view for an event using a specified font.

    Declaration

    Swift

    class func popUpContextMenu(_ menu: NSMenu, withEvent event: NSEvent, forView view: NSView, withFont font: NSFont?)

    Objective-C

    + (void)popUpContextMenu:(NSMenu *)menu withEvent:(NSEvent *)event forView:(NSView *)view withFont:(NSFont *)font

    Parameters

    menu

    The menu object to use for the contextual menu.

    event

    An NSEvent object representing the event.

    view

    The view object over which to display the contextual menu.

    font

    An NSFont object representing the font for the contextual menu. If you pass in nil for the font, the method uses the default font for menu.

    Discussion

    Specifying a font using the font parameter is discouraged. Instead set the menu’s font using the setFont: method and pass nil for the font parameter.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Overridden by subclasses to implement specialized context-sensitive help behavior.

    Declaration

    Swift

    func helpRequested(_ event: NSEvent)

    Objective-C

    - (void)helpRequested:(NSEvent *)event

    Parameters

    event

    An NSEvent object representing the event associated with the help request.

    Discussion

    Subclasses in their implementation of this method should cause the Help Manager (NSHelpManager) to display the help associated with the receiver. Never invoke this method directly.

    Special Considerations

    On OS X v10.6 and later this method has no effect. This method may be deprecated in a future release.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    showContextHelpForObject:locationHint: (NSHelpManager)

  • Pops up the menu at the specified location.

    Declaration

    Swift

    func popUpMenuPositioningItem(_ item: NSMenuItem?, atLocation location: NSPoint, inView view: NSView?) -> Bool

    Objective-C

    - (BOOL)popUpMenuPositioningItem:(NSMenuItem *)item atLocation:(NSPoint)location inView:(NSView *)view

    Parameters

    item

    The menu item to be positioned at the specified location in the view.

    location

    The location in the view coordinate system to display the menu item.

    view

    The view to display the menu item over.

    Return Value

    YEStrue if menu tracking ended because an item was selected, and NOfalse if menu tracking was cancelled for any reason.

    Discussion

    Pops up the receiver as a popup menu. The top left corner of the specified item (if specified, item must be present in the receiver) is positioned at the specified location in the specified view, interpreted in the view's own coordinate system.

    If item is nil, the menu is positioned such that the top left of the menu content frame is at the given location.

    If view is nil, the location is interpreted in the screen coordinate system. This allows you to pop up a menu disconnected from any window.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Sets whether the receiver displays the state column.

    Declaration

    Swift

    var showsStateColumn: Bool

    Objective-C

    @property BOOL showsStateColumn

    Parameters

    showsState

    YEStrue to display the state column, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns a Boolean value that indicates whether the receiver displays the state column.

    Declaration

    Swift

    var showsStateColumn: Bool

    Objective-C

    @property BOOL showsStateColumn

    Return Value

    YEStrue if the receiver displays the state column, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the zone from which NSMenu objects should be allocated.

    Declaration

    Swift

    class func menuZone() -> NSZone

    Objective-C

    + (NSZone *)menuZone

    Return Value

    The zone from which NSMenu objects should be allocated.

    Special Considerations

    This is left in for compatibility and always returns NSDefaultMallocZone. It is not necessary to use this.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the zone from which NSMenu objects should be allocated

    Declaration

    Objective-C

    + (void)setMenuZone:(NSZone *)zone

    Parameters

    zone

    The memory zone to set.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Returns the highlighted item in the receiver.

    Declaration

    Swift

    var highlightedItem: NSMenuItem? { get }

    Objective-C

    @property(readonly, strong) NSMenuItem *highlightedItem

    Return Value

    Returns the highlighted item in the receiver, or nil if no item in the menu is highlighted.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Sets the receiver’s delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSMenuDelegate?

    Objective-C

    @property(assign) id<NSMenuDelegate> delegate

    Parameters

    anObject

    The object to set as delegate.

    Discussion

    You can use the delegate to populate a menu just before it is going to be drawn and to check for key equivalents without creating a menu item.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – delegate

  • Returns the receiver’s delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSMenuDelegate?

    Objective-C

    @property(assign) id<NSMenuDelegate> delegate

    Return Value

    The receiver’s delegate.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Deprecated.

    Deprecation Statement

    OS X does not use menu representations to draw menus.

    Declaration

    Objective-C

    - (id)contextMenuRepresentation

    Return Value

    nil.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Deprecated.

    Deprecation Statement

    OS X does not use menu representations to draw menus.

    Declaration

    Objective-C

    - (void)setContextMenuRepresentation:(id)menuRep

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Deprecated.

    Deprecation Statement

    OS X does not use menu representations to draw menus.

    Declaration

    Objective-C

    - (id)tearOffMenuRepresentation

    Return Value

    nil.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Deprecated.

    Deprecation Statement

    OS X does not use menu representations to draw menus.

    Declaration

    Objective-C

    - (void)setTearOffMenuRepresentation:(id)menuRep

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Deprecated.

    Deprecation Statement

    OS X does not use menu representations to draw menus.

    Declaration

    Objective-C

    - (void)setMenuRepresentation:(id)menuRep

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • Deprecated.

    Deprecation Statement

    OS X does not use menu representations to draw menus.

    Declaration

    Objective-C

    - (id)menuRepresentation

    Return Value

    nil.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.2.

  • These constants are used as a bitmask for specifying a set of menu or menu item properties, used in the propertiesToUpdate.

    Declaration

    Swift

    struct NSMenuProperties : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var PropertyItemTitle: NSMenuProperties { get } static var PropertyItemAttributedTitle: NSMenuProperties { get } static var PropertyItemKeyEquivalent: NSMenuProperties { get } static var PropertyItemImage: NSMenuProperties { get } static var PropertyItemEnabled: NSMenuProperties { get } static var PropertyItemAccessibilityDescription: NSMenuProperties { get } }

    Objective-C

    enum { NSMenuPropertyItemTitle = 1 << 0, NSMenuPropertyItemAttributedTitle = 1 << 1 NSMenuPropertyItemKeyEquivalent = 1 << 2, NSMenuPropertyItemImage = 1 << 3, NSMenuPropertyItemEnabled = 1 << 4, NSMenuPropertyItemAccessibilityDescription = 1 << 5 }; typedef NSUInteger NSMenuProperties;

    Constants

    • PropertyItemTitle

      NSMenuPropertyItemTitle

      The menu item’s title.

      Available in OS X v10.6 and later.

    • PropertyItemAttributedTitle

      NSMenuPropertyItemAttributedTitle

      The menu item’s attributed string title.

      Available in OS X v10.6 and later.

    • PropertyItemKeyEquivalent

      NSMenuPropertyItemKeyEquivalent

      The menu item’s key equivalent.

      Available in OS X v10.6 and later.

    • PropertyItemImage

      NSMenuPropertyItemImage

      The menu image.

      Available in OS X v10.6 and later.

    • PropertyItemEnabled

      NSMenuPropertyItemEnabled

      Whether the menu item is enabled or disabled.

      Available in OS X v10.6 and later.

    • PropertyItemAccessibilityDescription

      NSMenuPropertyItemAccessibilityDescription

      The menu item’s accessibility description.

      Available in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted after a menu item is added to the menu. The notification object is the instance of NSMenu that just added the new menu item. The userInfo dictionary contains the following information:

    Key

    Value

    @"NSMenuItemIndex"

    An NSNumber object containing the integer index of the menu item that was added.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted after a menu item in the menu changes appearance. Changes include enabling/disabling, changes in state, and changes to title. The notification object is the instance of NSMenu with the menu item that changed. The userInfo dictionary contains the following information:

    Key

    Value

    @"NSMenuItemIndex"

    An NSNumber object containing the integer index of the menu item that changed.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted when menu tracking begins. The notification object is the main menu bar ([NSApp mainMenu]) or the root menu of a popup button. This notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Posted when menu tracking ends, even if no action is sent. The notification object is the main menu bar ([NSApp mainMenu]) or the root menu of a popup button. This notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Posted after a menu item is removed from the menu. The notification object is the instance of NSMenu that just removed the menu item. The userInfo dictionary contains the following information:

    Key

    Value

    @"NSMenuItemIndex"

    An NSNumber object containing the integer index of the menu item that was removed. Note that this index may no longer be valid and in any event no longer points to the menu item that was removed.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted just after the application dispatches a menu item’s action method to the menu item’s target. The notification object is the instance of NSMenu containing the chosen menu item. The userInfo dictionary contains the following information:

    Key

    Value

    @"MenuItem"

    The menu item that was chosen.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted just before the application dispatches a menu item’s action method to the menu item’s target. The notification object is the instance of NSMenu containing the chosen menu item. The userInfo dictionary contains the following information:

    Key

    Value

    @"MenuItem"

    The menu item that was chosen.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.