Class

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.

Overview

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

Symbols

Creating a Menu Item

init(title: String, action: Selector?, keyEquivalent: String)

Returns an initialized instance of an NSMenuItem.

Enabling a Menu Item

var isEnabled: Bool

A boolean that shows whether the receiver is enabled.

Managing Hidden Status

var isHidden: Bool

A boolean that indicates whether the receiver is hidden.

var isHiddenOrHasHiddenAncestor: Bool

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

Managing the Target and Action

var target: AnyObject?

The receiver’s target.

var action: Selector?

The receiver’s action-method selector.

Managing the Title

var title: String

The receiver’s title.

var attributedTitle: NSAttributedString?

A custom string for a menu item.

Managing the Tag

var tag: Int

The receiver’s tag.

Managing the State

var state: Int

The state of the receiver.

Managing the Image

var image: NSImage?

The receiver’s image.

var onStateImage: NSImage!

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

var offStateImage: NSImage?

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

var mixedStateImage: NSImage!

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

Managing Submenus

var submenu: NSMenu?

The submenu of the receiver.

var hasSubmenu: Bool

A Boolean value that indicates whether the receiver has a submenu.

var parent: NSMenuItem?

The menu item whose submenu contains the receiver.

Getting a Separator Item

var isSeparatorItem: Bool

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

class func separator()

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

Managing the Owning Menu

var menu: NSMenu?

The receiver’s menu.

Managing Key Equivalents

var keyEquivalent: String

The receiver’s unmodified key equivalent.

var keyEquivalentModifierMask: NSEventModifierFlags

The receiver’s keyboard equivalent modifiers.

Managing Mnemonics

func setTitleWithMnemonic(String)

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

Managing User Key Equivalents

class func setUsesUserKeyEquivalents(Bool)

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

class func usesUserKeyEquivalents()

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

var userKeyEquivalent: String

Tthe user-assigned key equivalent for the receiver.

Managing Alternates

var isAlternate: Bool

A boolean value that marks the receiver as an alternate to the previous menu item.

Managing Indentation Levels

var indentationLevel: Int

The menu item indentation level for the receiver.

Managing Tool Tips

var toolTip: String?

A help tag for a menu item.

Representing an Object

var representedObject: Any?

The object represented by the receiver.

Managing the View

var view: NSView?

The content view for the receiver.

Getting Highlighted Status

var isHighlighted: Bool

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