<!--
{
  "availability" : [
    "macOS: 10.12.2 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCandidateListTouchBarItem/setCandidates(_:forSelectedRange:in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSCandidateListTouchBarItem(im)setCandidates:forSelectedRange:inString:"
  },
  "title" : "setCandidates(_:forSelectedRange:in:)"
}
-->

# setCandidates(_:forSelectedRange:in:)

Sets an array of candidate objects to be displayed in the candidate list bar item.

```
func setCandidates(_ candidates: [CandidateType], forSelectedRange selectedRange: NSRange, in originalString: String?)
```

## Parameters

`candidates`

The array of candidates you wish to display in the candidate list item.

`selectedRange`

A range (<doc://com.apple.documentation/documentation/Foundation/NSRange-c.struct>) within the string that the candidates represent.

`originalString`

The original string from which the candidate list was derived.

## Discussion

The item uses the block in the [`attributedStringForCandidate`](/documentation/AppKit/NSCandidateListTouchBarItem/attributedStringForCandidate) property to convert each candidate in the array into an attributed string. If the value of the [`attributedStringForCandidate`](/documentation/AppKit/NSCandidateListTouchBarItem/attributedStringForCandidate) property is `nil` then [`NSCandidateListTouchBarItem`](/documentation/AppKit/NSCandidateListTouchBarItem) can format candidates of type <doc://com.apple.documentation/documentation/Foundation/NSString>, <doc://com.apple.documentation/documentation/Foundation/NSAttributedString>, and <doc://com.apple.documentation/documentation/Foundation/NSTextCheckingResult>.

---

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)