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

# textView(_:completions:forPartialWordRange:indexOfSelectedItem:)

Returns the actual completions for a partial word.

```
@MainActor optional func textView(_ textView: NSTextView, completions words: [String], forPartialWordRange charRange: NSRange, indexOfSelectedItem index: UnsafeMutablePointer<Int>?) -> [String]
```

## Parameters

`textView`

The text view sending the message.

`words`

The proposed array of completions.

`charRange`

The range of characters to be completed.

`index`

On return, the index of the initially selected completion. The default is 0, and –1 indicates no selection.

## Return Value

The actual array of completions that will be presented for the partial word at the given range. Returning `nil` or a zero-length array suppresses completion.

## Discussion

---

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)