<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSMenu/insertItem(_:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMenu(im)insertItem:atIndex:"
  },
  "title" : "insertItem(_:at:)"
}
-->

# insertItem(_:at:)

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

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

This method posts an [`didAddItemNotification`](/documentation/AppKit/NSMenu/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 <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/internalInconsistencyException>.

## See Also

[`item(at:)`](/documentation/AppKit/NSMenu/item(at:))

Returns the menu item at a specific location of the menu.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)