Mac Developer Library

Developer

AppKit Framework Reference NSMenuItem Class Reference

Options
Deployment Target:

On This Page
Language:

NSMenuItem

The NSMenuItem class defines objects that are used as command items in menus. Additionally, the NSMenuItem class also includes some private functionality needed to maintain binary compatibility with other components of Cocoa. Because of this fact, you cannot replace the NSMenuItem class with a different class. You may, however, subclass NSMenuItem if necessary.

Prior to OS X v10.5, NSMenuItem conformed to the following protocols: NSCopying (see NSCopying Protocol Reference), NSCoding (see NSCoding Protocol Reference), and NSValidatedUserInterfaceItem (see NSValidatedUserInterfaceItem Protocol Reference).

Inheritance


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns an initialized instance of an NSMenuItem.

    Declaration

    Swift

    init(title itemName: String, action anAction: Selector, keyEquivalent charCode: String)

    Objective-C

    - (instancetype)initWithTitle:(NSString *)itemName action:(SEL)anAction keyEquivalent:(NSString *)charCode

    Parameters

    itemName

    The title of the menu item. This value must not be nil (if there is no title, specify an empty NSString).

    anAction

    The action selector to be associated with the menu item. This value must be a valid selector or NULL.

    charCode

    A string representing a keyboard key to be used as the key equivalent. This value must not be nil (if there is no key equivalent, specify an empty NSString).

    Return Value

    An instance of NSMenuItem, or nil if the object couldn't be created.

    Discussion

    For instances of the NSMenuItem class, the default initial state is NSOffState, the default on-state image is a check mark, and the default mixed-state image is a dash.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets whether the receiver is enabled

    Declaration

    Swift

    var enabled: Bool

    Objective-C

    @property(getter=isEnabled) BOOL enabled

    Parameters

    flag

    YEStrue if the receiver is to be enabled, otherwise NOfalse.

    Discussion

    This method has no effect unless the menu in which the item will be added or is already a part of has been sent setAutoenablesItems:NO. If a menu item is disabled, its keyboard equivalent is also disabled. See the NSMenuValidation informal protocol specification for cautions regarding this method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – isEnabled

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

    Returns a Boolean value that indicates whether the receiver is enabled.

    Declaration

    Objective-C

    - (BOOL)isEnabled

    Return Value

    YEStrue if the receiver is enabled, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

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

    See Also

    – setEnabled:

  • Sets whether the receiver is hidden.

    Declaration

    Swift

    var hidden: Bool

    Objective-C

    @property(getter=isHidden) BOOL hidden

    Parameters

    hidden

    YEStrue if the receiver is to be hidden, otherwise NOfalse.

    Discussion

    Hidden menu items (or items with a hidden superitem) do not appear in a menu and do not participate in command key matching.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • isHidden - isHidden Available in OS X v10.5 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver is hidden.

    Declaration

    Objective-C

    - (BOOL)isHidden

    Return Value

    YEStrue if the receiver is hidden, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

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

  • isHiddenOrHasHiddenAncestor - isHiddenOrHasHiddenAncestor Available in OS X v10.5 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver or any of its superitems is hidden.

    Declaration

    Objective-C

    - (BOOL)isHiddenOrHasHiddenAncestor

    Return Value

    YEStrue if the receiver or any of its superitems is hidden, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

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

  • Sets the receiver’s target.

    Declaration

    Swift

    weak var target: AnyObject?

    Objective-C

    @property(weak) id target

    Parameters

    anObject

    An object to be the target of action messages sent by the receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s target.

    Declaration

    Swift

    weak var target: AnyObject?

    Objective-C

    @property(weak) id target

    Return Value

    The receiver’s target.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s action-method selector.

    Declaration

    Swift

    var action: Selector

    Objective-C

    @property SEL action

    Parameters

    aSelector

    A selector identifying the action method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s action-method selector.

    Declaration

    Swift

    var action: Selector

    Objective-C

    @property SEL action

    Return Value

    The receiver’s action-method selector.

    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

    The new title of the menu item. If you do not want a title, use an empty string (@""), not nil.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • 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:

  • Specifies a custom string for a menu item.

    Declaration

    Swift

    @NSCopying var attributedTitle: NSAttributedString?

    Objective-C

    @property(copy) NSAttributedString *attributedTitle

    Parameters

    string

    An attributed string to use as the receiver's title.

    Discussion

    You can use this method to add styled text and embedded images to menu item strings. If you do not set a text color for the attributed string, it is black when not selected, white when selected, and gray when disabled. Colored text remains unchanged when selected.

    When you call this method to set the menu title to an attributed string, the setTitle: method is also called to set the menu title with a plain string. If you clear the attributed title, the plain title remains unchanged. To clear the attributed title, set the attributed string to either nil or an empty attributed string ([attrStr length] == 0).

    The attributed string is not archived in the old nib format.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the custom title string for a menu item.

    Declaration

    Swift

    @NSCopying var attributedTitle: NSAttributedString?

    Objective-C

    @property(copy) NSAttributedString *attributedTitle

    Return Value

    The custom title string for a menu item.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets the receiver’s tag.

    Declaration

    Swift

    var tag: Int

    Objective-C

    @property NSInteger tag

    Parameters

    anInt

    An integer tag to associate with the receiver.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s tag.

    Declaration

    Swift

    var tag: Int

    Objective-C

    @property NSInteger tag

    Return Value

    The receiver’s tag.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the state of the receiver.

    Declaration

    Swift

    var state: Int

    Objective-C

    @property NSInteger state

    Parameters

    itemState

    An integer constant representing a state; it should be one of NSOffState, NSOnState, or NSMixedState.

    Discussion

    The image associated with the new state is displayed to the left of the menu item.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the state of the receiver.

    Declaration

    Swift

    var state: Int

    Objective-C

    @property NSInteger state

    Return Value

    The state of the receiver—one of NSOffState (the default), NSOnState, or NSMixedState.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setState:

  • Sets the receiver’s image.

    Declaration

    Swift

    var image: NSImage?

    Objective-C

    @property(strong) NSImage *image

    Parameters

    menuImage

    An NSImage object representing an image to be displayed in the menu item. If menuImage is nil, the current image (if any) is removed.

    Discussion

    The menu item's image is not affected by changes in its state.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – image

  • Returns the image displayed by the receiver.

    Declaration

    Swift

    var image: NSImage?

    Objective-C

    @property(strong) NSImage *image

    Return Value

    The image displayed by the receiver, or nil if it displays no image.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setImage:

  • Sets the image of the receiver that indicates an “on” state.

    Declaration

    Swift

    var onStateImage: NSImage!

    Objective-C

    @property(strong) NSImage *onStateImage

    Parameters

    itemImage

    The NSImage object to use for the "on" state of the menu item. If itemImage is nil, any current on-state image is removed.

    Discussion

    Changing state images is currently unsupported in OS X.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the image used to depict the receiver’s “on” state.

    Declaration

    Swift

    var onStateImage: NSImage!

    Objective-C

    @property(strong) NSImage *onStateImage

    Return Value

    The image used to depict the receiver’s “on” state, or nil if the image has not been set.

    Discussion

    By default this image is a check mark.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the image of the receiver that indicates an “off” state.

    Declaration

    Swift

    var offStateImage: NSImage!

    Objective-C

    @property(strong) NSImage *offStateImage

    Parameters

    itemImage

    The NSImage object to use for the "off" state of the menu item. If itemImage is nil, any current off-state image is removed.

    Discussion

    Changing state images is currently unsupported in OS X.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the image used to depict the receiver’s “off” state.

    Declaration

    Swift

    var offStateImage: NSImage!

    Objective-C

    @property(strong) NSImage *offStateImage

    Return Value

    The image used to depict the receiver’s “off” state, or nil if the image has not been set.

    Discussion

    By default there is no off-state image.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the image of the receiver that indicates a “mixed” state, that is, a state neither “on” nor “off.”

    Declaration

    Swift

    var mixedStateImage: NSImage!

    Objective-C

    @property(strong) NSImage *mixedStateImage

    Parameters

    itemImage

    The NSImage object to use for the "mixed" state of the menu item. If itemImage is nil, any current mixed-state image is removed.

    Discussion

    Changing state images is currently unsupported in OS X.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the image used to depict a “mixed state.”

    Declaration

    Swift

    var mixedStateImage: NSImage!

    Objective-C

    @property(strong) NSImage *mixedStateImage

    Return Value

    The image used to depict a “mixed state.”

    Discussion

    A mixed state is useful for indicating a mix of “off” and “on” attribute values in a group of selected objects, such as a selection of text containing boldface and plain (non-boldface) words. By default this is a horizontal line.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the submenu of the receiver.

    Declaration

    Swift

    var submenu: NSMenu?

    Objective-C

    @property(strong) NSMenu *submenu

    Parameters

    aSubmenu

    The menu object to set as submenu.

    Discussion

    The default implementation of the NSMenuItem class raises an exception if aSubmenu already has a supermenu.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the submenu associated with the receiving menu item.

    Declaration

    Swift

    var submenu: NSMenu?

    Objective-C

    @property(strong) NSMenu *submenu

    Return Value

    The submenu associated with the receiving menu item, or nil if no submenu is associated with it.

    Discussion

    If the receiver responds YEStrue to hasSubmenu, the submenu is returned.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether the receiver has a submenu.

    Declaration

    Swift

    var hasSubmenu: Bool { get }

    Objective-C

    @property(readonly) BOOL hasSubmenu

    Return Value

    YEStrue if the receiver has a submenu, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    setSubmenu:forItem: (NSMenu)

  • Returns the menu item whose submenu contains the receiver.

    Declaration

    Swift

    unowned(unsafe) var parentItem: NSMenuItem? { get }

    Objective-C

    @property(readonly, assign) NSMenuItem *parentItem

    Return Value

    The parent menu item, or nil if the receiver does not have a parent item.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns a menu item that is used to separate logical groups of menu commands.

    Declaration

    Swift

    class func separatorItem() -> NSMenuItem

    Objective-C

    + (NSMenuItem *)separatorItem

    Return Value

    A menu item that is used to separate logical groups of menu commands.

    Discussion

    This menu item is disabled. The default separator item is blank space.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

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

    Returns a Boolean value that indicates whether the receiver is a separator item.

    Declaration

    Objective-C

    - (BOOL)isSeparatorItem

    Return Value

    YEStrue if the receiver is a separator item (that is, a menu item used to visually segregate related menu items), otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

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

  • Sets the receiver’s menu.

    Declaration

    Swift

    unowned(unsafe) var menu: NSMenu?

    Objective-C

    @property(assign) NSMenu *menu

    Parameters

    aMenu

    The menu object that "owns" the receiver.

    Discussion

    This method is invoked by the owning NSMenu object when the receiver is added or removed. You shouldn’t have to invoke this method in your own code, although it can be overridden to provide specialized behavior.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – menu

  • Returns the menu to which the receiver belongs.

    Declaration

    Swift

    unowned(unsafe) var menu: NSMenu?

    Objective-C

    @property(assign) NSMenu *menu

    Return Value

    The menu to which the receiver belongs, or nil if no menu has been set.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setMenu:

  • Sets the receiver’s unmodified key equivalent.

    Declaration

    Swift

    var keyEquivalent: String

    Objective-C

    @property(copy) NSString *keyEquivalent

    Parameters

    aString

    A string containing a character code representing a keyboard key. If you want to remove the key equivalent from a menu item, pass an empty string (@"") for aString (never pass nil).

    Discussion

    This method considers the case of the letter passed to determine if it has a Shift modifier added. That is, [item setKeyEquivalent:@"w"] sets the key equivalent to Command-w, while [item setKeyEquivalent:@"W"] is Command-Shift-w. You use setKeyEquivalentModifierMask: to set the appropriate mask for the modifier keys for the key equivalent.

    If you want to specify the Backspace key as the key equivalent for a menu item, use a single character string with NSBackspaceCharacter (defined in NSText.h as 0x08) and for the Forward Delete key, use NSDeleteCharacter (defined in NSText.h as 0x7F). Note that these are not the same characters you get from an NSEvent key-down event when pressing those keys.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s unmodified keyboard equivalent.

    Declaration

    Swift

    var keyEquivalent: String

    Objective-C

    @property(copy) NSString *keyEquivalent

    Return Value

    The receiver’s unmodified keyboard equivalent, or the empty string if one hasn’t been defined.

    Discussion

    Use keyEquivalentModifierMask to determine the modifier mask for the key equivalent.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s keyboard equivalent modifiers.

    Declaration

    Swift

    var keyEquivalentModifierMask: Int

    Objective-C

    @property NSUInteger keyEquivalentModifierMask

    Parameters

    mask

    The key masks indicate modifiers such as the Shift or Option keys. mask is an integer bit field containing any of these modifier key masks, combined using the C bitwise OR operator:

    • NSShiftKeyMask

    • NSAlternateKeyMask

    • NSCommandKeyMask

    • NSControlKeyMask

    Discussion

    In general, you are strongly encouraged to always set NSCommandKeyMask in mask, although there may be some conventions where this is not required. For example, in an application that plays media, the Play command may be mapped to just “ ” (space), without the command key. You can do this with the following code:

    • [menuItem setKeyEquivalent:@" "];
    • [menuItem setKeyEquivalentModifierMask:0];

    NSShiftKeyMask is a valid modifier for any key equivalent in mask. This allows you to specify key-equivalents such as Command-Shift-1 that are consistent across all keyboards. However, with a few exceptions (such as the German “ß” character), a lowercase character with NSShiftKeyMask is interpreted the same as the uppercase character without that mask. For example, Command-Shift-c and Command-C are considered to be identical key equivalents.

    See the NSEvent class specification for more information about modifier mask values.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s keyboard equivalent modifier mask.

    Declaration

    Swift

    var keyEquivalentModifierMask: Int

    Objective-C

    @property NSUInteger keyEquivalentModifierMask

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Deprecated. Sets the character of the menu item title at location that is to be underlined.

    Declaration

    Objective-C

    - (void)setMnemonicLocation:(NSUInteger)location

    Parameters

    location

    An integer index into the character array of the title. location must be from 0 to 254.

    Discussion

    This character identifies the access key by which users can access the menu item.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Deprecated. Returns the position of the underlined character in the menu item title used as a mnemonic.

    Declaration

    Objective-C

    - (NSUInteger)mnemonicLocation

    Discussion

    The position is the zero-based index of that character in the title string. If the receiver has no mnemonic character, returns NSNotFound.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Deprecated. Sets the title of a menu item with a character denoting an access key.

    Declaration

    Swift

    func setTitleWithMnemonic(_ stringWithAmpersand: String)

    Objective-C

    - (void)setTitleWithMnemonic:(NSString *)stringWithAmpersand

    Discussion

    Use an ampersand character to mark the character (the one following the ampersand) to be designated.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • mnemonic - mnemonic (OS X v10.6)

    Deprecated. Returns the character in the menu item title that appears underlined for use as a mnemonic.

    Declaration

    Objective-C

    - (NSString *)mnemonic

    Discussion

    If there is no mnemonic character, returns an empty string.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Sets whether menu items conform to user preferences for key equivalents.

    Declaration

    Swift

    class func setUsesUserKeyEquivalents(_ flag: Bool)

    Objective-C

    + (void)setUsesUserKeyEquivalents:(BOOL)flag

    Parameters

    flag

    If YEStrue, menu items conform to user preferences for key equivalents; otherwise, the key equivalents originally assigned to the menu items are used.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns a Boolean value that indicates whether menu items conform to user preferences for key equivalents.

    Declaration

    Swift

    class func usesUserKeyEquivalents() -> Bool

    Objective-C

    + (BOOL)usesUserKeyEquivalents

    Return Value

    YEStrue if menu items conform to user preferences for key equivalents, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the user-assigned key equivalent for the receiver.

    Declaration

    Swift

    var userKeyEquivalent: String { get }

    Objective-C

    @property(readonly, copy) NSString *userKeyEquivalent

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Marks the receiver as an alternate to the previous menu item.

    Declaration

    Swift

    var alternate: Bool

    Objective-C

    @property(getter=isAlternate) BOOL alternate

    Parameters

    isAlternate

    YEStrue if the receiver is an alternate to the previous menu item, NOfalse otherwise.

    Discussion

    If the receiver has the same key equivalent as the previous item, but has different key equivalent modifiers, the items are folded into a single visible item and the appropriate item shows while tracking the menu, depending on what modifier key (if any) is pressed. The menu items may also have no key equivalent as long as the key equivalent modifiers are different.

    Consider the following example: menuItem1 and menuItem2 are menu items in the same menu, with menuItem1 above menuItem2:

    • [menuItem1 setTitle:@"One"];
    • [menuItem1 setKeyEquivalent:@"t"];
    • [menuItem2 setTitle:@"Two"];
    • [menuItem2 setKeyEquivalent:@"T"];
    • [menuItem2 setAlternate:YES];

    When the menu is displayed, it shows only menuItem1 (with title “One”) instead of two menu items. If the user presses the Shift key while the menu is displayed, menuItem2 (with title “Two”) replaces “One”.

    If there are two or more items with no key equivalent but different modifiers, then the only way to get access to the alternate items is with the mouse. In the following example,“Two” is shown only if the user presses the Alternate key.

    • [menuItem1 setKeyEquivalent:@""];
    • [menuItem1 setTitle:@"One"];
    • [menuItem2 setKeyEquivalent:@""];
    • [menuItem2 setKeyEquivalentModifierMask:NSAlternateKeyMask];
    • [menuItem2 setTitle:@"Two"];

    If you mark items as alternates but their key equivalents don’t match, they might be displayed as separate items. Marking the first item as an alternate has no effect.

    The isAlternate value is archived.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – isAlternate

  • isAlternate - isAlternate Available in OS X v10.3 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver is an alternate to the previous menu item.

    Declaration

    Objective-C

    - (BOOL)isAlternate

    Return Value

    YEStrue if the receiver is an alternate to the previous menu item, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

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

  • Sets the menu item indentation level for the receiver.

    Declaration

    Swift

    var indentationLevel: Int

    Objective-C

    @property NSInteger indentationLevel

    Parameters

    indentationLevel

    The value for indentationLevel may be from 0 to 15. If indentationLevel is greater than 15, the value is pinned to the maximum. If indentationLevel is less than 0, an exception is raised. The default indentation level is 0.

    Discussion

    The indentationLevel value is archived.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Returns the menu item indentation level for the receiver.

    Declaration

    Swift

    var indentationLevel: Int

    Objective-C

    @property NSInteger indentationLevel

    Discussion

    The return value is from 0 to 15. The default indentation level is 0.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Sets a help tag for a menu item.

    Declaration

    Swift

    var toolTip: String?

    Objective-C

    @property(copy) NSString *toolTip

    Parameters

    toolTip

    A short string that describes the menu item.

    Discussion

    You can invoke this method for any menu item, including items in the main menu bar. This string is not archived in the old nib format.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – toolTip

  • Returns the help tag for a menu item.

    Declaration

    Swift

    var toolTip: String?

    Objective-C

    @property(copy) NSString *toolTip

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

    See Also

    – setToolTip:

  • Sets the object represented by the receiver.

    Declaration

    Swift

    var representedObject: AnyObject?

    Objective-C

    @property(strong) id representedObject

    Parameters

    anObject

    The object to be represented by the receiver.

    Discussion

    By setting a represented object for a menu item, you make an association between the menu item and that object. The represented object functions as a more specific form of tag that allows you to associate any object, not just an arbitrary integer, with the items in a menu.

    For example, an NSView object might be associated with a menu item—when the user chooses the menu item, the represented object is fetched and displayed in a panel. Several menu items might control the display of multiple views in the same panel.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the object that the receiving menu item represents.

    Declaration

    Swift

    var representedObject: AnyObject?

    Objective-C

    @property(strong) id representedObject

    Discussion

    For example, you might have a menu list the names of views that are swapped into the same panel. The represented objects would be the appropriate NSView objects. The user would then be able to switch back and forth between the different views that are displayed by selecting the various menu items.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the content view for the receiver.

    Declaration

    Swift

    var view: NSView?

    Objective-C

    @property(strong) NSView *view

    Parameters

    view

    The content view for the receiver.

    Discussion

    A menu item with a view does not draw its title, state, font, or other standard drawing attributes, and assigns drawing responsibility entirely to the view. Keyboard equivalents and type-select continue to use the key equivalent and title as normal. For more details, see Application Menu and Pop-up List Programming Topics.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    See Also

    – view

  • Returns the view for the receiver.

    Declaration

    Swift

    var view: NSView?

    Objective-C

    @property(strong) NSView *view

    Return Value

    The view for the receiver.

    Discussion

    By default, a menu item has a nil view.

    See setView: for more details.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

    See Also

    – setView:

  • isHighlighted - isHighlighted Available in OS X v10.5 through OS X v10.9

    Returns a Boolean value that indicates whether the receiver should be drawn highlighted.

    Declaration

    Objective-C

    - (BOOL)isHighlighted

    Return Value

    YEStrue if the receiver should be drawn highlighted, otherwise NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

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