---
title: "indexOfItem(withTarget:andAction:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nspopupbutton/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. This method invokes the method of the same name of its NSPopUpButtonCell object.

## See Also

### Getting the indices of menu items

- [index(of:)](appkit/nspopupbutton/index(of:).md)
- [indexOfItem(withTag:)](appkit/nspopupbutton/indexofitem(withtag:).md)
- [indexOfItem(withTitle:)](appkit/nspopupbutton/indexofitem(withtitle:).md)
- [indexOfItem(withRepresentedObject:)](appkit/nspopupbutton/indexofitem(withrepresentedobject:).md)
