<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTokenField",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTokenField"
  },
  "title" : "NSTokenField"
}
-->

# NSTokenField

A text field that converts text into visually distinct tokens.

```
class NSTokenField
```

## Overview

Use a token field when you want typed text to be transformed into “tokens”, which are visually distinct elements in the text field interface. For example, you might use a token field in a mail app to display email addresses for individual users. The distinct appearance of tokens makes them easy for users to distinguish from surrounding text.

`NSTokenField` uses an [`NSTokenFieldCell`](/documentation/AppKit/NSTokenFieldCell) to implement much of the control’s functionality. `NSTokenField` provides cover methods for most methods of `NSTokenFieldCell`, which invoke the corresponding cell method.

> Notes:
> In OS X v10.4 and earlier, represented objects associated with token fields had to conform to <doc://com.apple.documentation/documentation/Foundation/NSCoding>. Starting with OS X v10.5, they no longer need to.
> 
> In OS X v10.4, `NSTokenField` trims whitespace around tokens but it does not trim whitespace in macOS versions 10.5.0 and 10.5.1. In OS X v10.5.2, you get whitespace-trimming behavior by either linking against the v10.4 binary or linking against the v10.5 binary and *not* implementing the ``doc://com.apple.appkit/documentation/AppKit/NSTokenFieldDelegate/tokenField(_:representedObjectForEditing:)`` method. If you do not want the whitespace-trimming behavior, link against the v10.5 binary and implement this method, returning the editing string if you have no represented object.

## Topics

### Configuring the Token Style

[`tokenStyle`](/documentation/AppKit/NSTokenField/tokenStyle-swift.property)

The token style of the receiver.

### Configuring the Tokenizing Character Set

[`tokenizingCharacterSet`](/documentation/AppKit/NSTokenField/tokenizingCharacterSet)

The recevier’s tokenizing character set to `characterSet`.

[`defaultTokenizingCharacterSet`](/documentation/AppKit/NSTokenField/defaultTokenizingCharacterSet)

Returns the default tokenizing character set.

### Configuring the Completion Delay

[`completionDelay`](/documentation/AppKit/NSTokenField/completionDelay)

The receiver’s completion delay.

[`defaultCompletionDelay`](/documentation/AppKit/NSTokenField/defaultCompletionDelay)

Returns the default completion delay.

### Getting and Setting the Delegate

[`delegate`](/documentation/AppKit/NSTokenField/delegate)

Returns the token field’s delegate.

### Enumerations

[`TokenStyle`](/documentation/AppKit/NSTokenField/TokenStyle-swift.enum)

The NSTokenStyle constants define how tokens are displayed and editable in the `NSTokenFieldCell`. These values are used by [`tokenStyle`](/documentation/AppKit/NSTokenFieldCell/tokenStyle) and the delegate method [`tokenFieldCell(_:styleForRepresentedObject:)`](/documentation/AppKit/NSTokenFieldCellDelegate/tokenFieldCell(_:styleForRepresentedObject:)).

## Relationships

### Conforms To

[`NSAccessibilityElementProtocol`](/documentation/AppKit/NSAccessibilityElementProtocol)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSUserActivityRestoring`](/documentation/AppKit/NSUserActivityRestoring)

[`NSStandardKeyBindingResponding`](/documentation/AppKit/NSStandardKeyBindingResponding)

[`NSUserInterfaceValidations`](/documentation/AppKit/NSUserInterfaceValidations)

[`NSAccessibilityStaticText`](/documentation/AppKit/NSAccessibilityStaticText)

[`NSAccessibilityNavigableStaticText`](/documentation/AppKit/NSAccessibilityNavigableStaticText)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSDraggingDestination`](/documentation/AppKit/NSDraggingDestination)

[`NSAccessibilityProtocol`](/documentation/AppKit/NSAccessibilityProtocol)

[`NSTextContent`](/documentation/AppKit/NSTextContent)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`NSTouchBarProvider`](/documentation/AppKit/NSTouchBarProvider)

[`Hashable`](/documentation/Swift/Hashable)

[`NSAnimatablePropertyContainer`](/documentation/AppKit/NSAnimatablePropertyContainer)

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSAppearanceCustomization`](/documentation/AppKit/NSAppearanceCustomization)

[`NSUserInterfaceItemIdentification`](/documentation/AppKit/NSUserInterfaceItemIdentification)

### Inherits From

[`NSTextField`](/documentation/AppKit/NSTextField)

---

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)