---
title: "indexOfItem(withTarget:andAction:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nspopupbuttoncell/indexofitem(withtarget:andaction:)"
---

# indexOfItem(withTarget:andAction:)

Returns the index of the menu item with the specified target and action.

## Declaration

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

## Parameters

- `target`: The target object associated with the menu item.
- `actionSelector`: The action method associated with the menu item.

## Return Value

Return Value The index of the menu item, or -1 if no menu item contains the specified target and action.

## Discussion

Discussion If you specify NULL for the actionSelector parameter, the index of the first menu item with the specified target is returned. The NSPopUpButtonCell class assigns a default action and target to each menu item, but you can change these values using the setAction: and setTarget: methods of NSMenuItem.

## See Also

### Related Documentation

- [indexOfSelectedItem](appkit/nspopupbuttoncell/indexofselecteditem.md)

### Accessing the items

- [itemArray](appkit/nspopupbuttoncell/itemarray.md)
- [numberOfItems](appkit/nspopupbuttoncell/numberofitems.md)
- [index(of:)](appkit/nspopupbuttoncell/index(of:).md)
- [indexOfItem(withTitle:)](appkit/nspopupbuttoncell/indexofitem(withtitle:).md)
- [indexOfItem(withTag:)](appkit/nspopupbuttoncell/indexofitem(withtag:).md)
- [indexOfItem(withRepresentedObject:)](appkit/nspopupbuttoncell/indexofitem(withrepresentedobject:).md)
- [item(at:)](appkit/nspopupbuttoncell/item(at:).md)
- [item(withTitle:)](appkit/nspopupbuttoncell/item(withtitle:).md)
- [lastItem](appkit/nspopupbuttoncell/lastitem.md)
