---
title: "insertItem(withTitle:action:keyEquivalent:at:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsmenu/insertitem(withtitle:action:keyequivalent:at:)"
---

# insertItem(withTitle:action:keyEquivalent:at:)

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

## Declaration

```swift
func insertItem(withTitle string: String, action selector: Selector?, keyEquivalent charCode: String, at index: Int) -> NSMenuItem
```

## Parameters

- `string`: A string to be made the title of the menu item.
- `selector`: The action-message selector to assign to the menu item.
- `charCode`: 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

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

## See Also

### Adding and Removing Menu Items

- [insertItem(_:at:)](appkit/nsmenu/insertitem(_:at:).md)
- [addItem(_:)](appkit/nsmenu/additem(_:).md)
- [addItem(withTitle:action:keyEquivalent:)](appkit/nsmenu/additem(withtitle:action:keyequivalent:).md)
- [removeItem(_:)](appkit/nsmenu/removeitem(_:).md)
- [removeItem(at:)](appkit/nsmenu/removeitem(at:).md)
- [itemChanged(_:)](appkit/nsmenu/itemchanged(_:).md)
- [removeAllItems()](appkit/nsmenu/removeallitems().md)
