<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSComboBoxDataSource/comboBox(_:indexOfItemWithStringValue:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSComboBoxDataSource(im)comboBox:indexOfItemWithStringValue:"
  },
  "title" : "comboBox(_:indexOfItemWithStringValue:)"
}
-->

# comboBox(_:indexOfItemWithStringValue:)

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

```
@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 implements[`comboBox(_:completedString:)`](/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

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

## 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.

---

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)