---
title: "insertItem(_:at:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsmenu/insertitem(_:at:)"
---

# insertItem(_:at:)

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

## Declaration

```swift
func insertItem(_ newItem: NSMenuItem, at index: Int)
```

## 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

Discussion This method posts an didAddItemNotification, 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 internalInconsistencyException.

## See Also

### Related Documentation

- [item(at:)](appkit/nsmenu/item(at:).md)

### Adding and Removing Menu Items

- [insertItem(withTitle:action:keyEquivalent:at:)](appkit/nsmenu/insertitem(withtitle:action:keyequivalent: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)
