---
title: "comboBox(_:indexOfItemWithStringValue:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nscomboboxdatasource/combobox(_:indexofitemwithstringvalue:)"
---

# comboBox(_:indexOfItemWithStringValue:)

Returns the index of the combo box item matching the specified string.

## Declaration

```swift
@MainActor optional func comboBox(_ comboBox: NSComboBox, indexOfItemWithStringValue string: String) -> Int
```

## Parameters

- `comboBox`: The combo box.
- `string`: The string to match against the items in the combo box. If the datasource implementsdoc://com.apple.appkit/documentation/AppKit/NSComboBoxDataSource/comboBox(_:completedString:), this is the string returned by that method. Otherwise, it is the text that the user has typed.

## Return Value

Return Value The index for the item that matches the specified string, or NSNotFound if no item matches.

## Discussion

Discussion An NSComboBox object uses this method to synchronize the pop-up list’s selected item with the text field’s contents.  If you don’t implement this method the receiver does not synchronize the pop-up list’s selected item with the text field’s contents.

## See Also

### Instance Methods

- [comboBox(_:completedString:)](appkit/nscomboboxdatasource/combobox(_:completedstring:).md)
- [comboBox(_:objectValueForItemAt:)](appkit/nscomboboxdatasource/combobox(_:objectvalueforitemat:).md)
- [numberOfItems(in:)](appkit/nscomboboxdatasource/numberofitems(in:).md)
