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

# indexOfItem(withTarget:andAction:)

Returns the index of the first menu item in the menu that has a specified action and target.

```
func indexOfItem(withTarget target: Any?, andAction actionSelector: Selector?) -> Int
```

## Parameters

`target`

An object that is set as the target of a menu item of the menu.

`actionSelector`

A selector identifying an action method. If `actionSelector` is `NULL`, the first menu item in the menu that has target `anObject` is returned.

## Return Value

The integer index of the menu item or, if no such menu item is in the menu, –1.

## See Also

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

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

[`-  insertItem:atIndex:`](/documentation/AppKit/NSMenu/insertItem(_:at:))

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



---

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)