Class

NSMenuItem

Defines objects that are used as command items in menus.

Overview

The NSMenuItem class 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, but you can subclass it if necessary. (Prior to OS X v10.5, NSMenuItem conformed to NSCopying, NSCoding, and NSValidatedUserInterfaceItem.)

Symbols

Creating a Menu Item

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

Returns an initialized instance of NSMenuItem.

Enabling a Menu Item

var isEnabled: Bool

A Boolean value that indicates whether the menu item is enabled.

Managing Hidden Status

var isHidden: Bool

A Boolean value that indicates whether the menu item is hidden.

var isHiddenOrHasHiddenAncestor: Bool

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

Managing the Target and Action

var target: AnyObject?

The menu item's target.

var action: Selector?

The menu item's action-method selector.

Managing the Title

var title: String

The menu item's title.

var attributedTitle: NSAttributedString?

A custom string for a menu item.

Managing the Tag

var tag: Int

The menu item's tag.

Managing the State

var state: Int

The state of the menu item.

Managing the Image

var image: NSImage?

The menu item’s image.

var onStateImage: NSImage!

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

var offStateImage: NSImage?

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

var mixedStateImage: NSImage!

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

Managing Submenus

var submenu: NSMenu?

The submenu of the menu item.

var hasSubmenu: Bool

A Boolean value that indicates whether the menu item 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 menu item’s menu.

Managing Key Equivalents

var keyEquivalent: String

The menu item’s unmodified key equivalent.

var keyEquivalentModifierMask: NSEventModifierFlags

The menu item’s keyboard equivalent modifiers.

Managing Mnemonics

func setTitleWithMnemonic(String)

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

The user-assigned key equivalent for the menu item.

Managing Alternates

var isAlternate: Bool

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

Managing Indentation Levels

var indentationLevel: Int

The menu item indentation level for the menu item.

Managing Tool Tips

var toolTip: String?

A help tag for the menu item.

Representing an Object

var representedObject: Any?

The object represented by the menu item.

Managing the View

var view: NSView?

The content view for the menu item.

Getting Highlighted Status

var isHighlighted: Bool

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