---
title: NSTokenField
framework: appkit
role: symbol
role_heading: Class
path: appkit/nstokenfield
---

# NSTokenField

A text field that converts text into visually distinct tokens.

## Declaration

```swift
class NSTokenField
```

## Overview

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 to implement much of the control’s functionality. NSTokenField provides cover methods for most methods of NSTokenFieldCell, which invoke the corresponding cell method. note: In OS X v10.4 and earlier, represented objects associated with token fields had to conform to 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 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](appkit/nstokenfield/tokenstyle-swift.property.md)

### Configuring the Tokenizing Character Set

- [tokenizingCharacterSet](appkit/nstokenfield/tokenizingcharacterset.md)
- [defaultTokenizingCharacterSet](appkit/nstokenfield/defaulttokenizingcharacterset.md)

### Configuring the Completion Delay

- [completionDelay](appkit/nstokenfield/completiondelay.md)
- [defaultCompletionDelay](appkit/nstokenfield/defaultcompletiondelay.md)

### Getting and Setting the Delegate

- [delegate](appkit/nstokenfield/delegate.md)

### Enumerations

- [NSTokenField.TokenStyle](appkit/nstokenfield/tokenstyle-swift.enum.md)

## Relationships

### Inherits From

- [NSTextField](appkit/nstextfield.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSAccessibilityElementProtocol](appkit/nsaccessibilityelementprotocol.md)
- [NSAccessibilityNavigableStaticText](appkit/nsaccessibilitynavigablestatictext.md)
- [NSAccessibilityProtocol](appkit/nsaccessibilityprotocol.md)
- [NSAccessibilityStaticText](appkit/nsaccessibilitystatictext.md)
- [NSAnimatablePropertyContainer](appkit/nsanimatablepropertycontainer.md)
- [NSAppearanceCustomization](appkit/nsappearancecustomization.md)
- [NSCoding](foundation/nscoding.md)
- [NSDraggingDestination](appkit/nsdraggingdestination.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSStandardKeyBindingResponding](appkit/nsstandardkeybindingresponding.md)
- [NSTextContent](appkit/nstextcontent.md)
- [NSTouchBarProvider](appkit/nstouchbarprovider.md)
- [NSUserActivityRestoring](appkit/nsuseractivityrestoring.md)
- [NSUserInterfaceItemIdentification](appkit/nsuserinterfaceitemidentification.md)
- [NSUserInterfaceValidations](appkit/nsuserinterfacevalidations.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
