<!--
{
  "availability" : [
    "macOS: 15.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextSuggestionsDelegate/textField(_:textCompletionFor:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "s:6AppKit25NSTextSuggestionsDelegateP9textField_0F13CompletionForSSSgSo0cG0C_AA16NSSuggestionItemVy010SuggestionK4TypeQzGtF"
  },
  "title" : "textField(_:textCompletionFor:)"
}
-->

# textField(_:textCompletionFor:)

Returns the full completion text for a particular item to use when the item is highlighted or selected.

```
@MainActor func textField(_ textField: NSTextField, textCompletionFor item: Self.Item) -> String?
```

## Parameters

`textField`

The text field whose suggestions item may be highlighted or selected.

`item`

The item that may be highlighted or selected.

## Return Value

The full text to insert, including the matched partial word and its potential completion, or `nil` if no text completion should be used.

## Discussion

This function may be used by the control to display a preview of the text that would appear if the highlighted item is selected. Additionally, the default implementation of `textField(_:didSelect:)` uses this function to inform what changes are made to the control’s text.

For example, given a user interface with a text field and suggestions menu that looks like:

```
        ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
Recipe: ┃ apple│                       ┃
        ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
        ┌────────────────┐
        │ Applesauce     │
        │ Apple juice    │
        │ Apple pie      │
        └────────────────┘
```

where “│” denotes the text insertion point.

If this function returns `"Applesauce"` for the first suggestion item, when the first suggestion item is highlighted, the user interface will look like:

```
        ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
Recipe: ┃ apple│sauce|                 ┃
        ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
        ┌────────────────┐
        │|Applesauce    |│
        │ Apple juice    │
        │ Apple pie      │
        └────────────────┘
```

where the text between “|” is shown as a preview in the field

Upon selection of that first suggestion item:

```
        ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
Recipe: ┃ Applesauce                   ┃
        ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
```

> Note: This function may or may not be called when an item is highlighted, depending on a variety of factors. Don’t depend upon the timing of when this function is called. Solely use it to return the full completion text for a particular item.

---

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)