A text field that converts text into visually distinct tokens.
SDK
- macOS 10.4+
Framework
- App
Kit
Declaration
class NSTokenField : NSText Field
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.
NSToken
uses an NSToken
to implement much of the control’s functionality. NSToken
provides cover methods for most methods of NSToken
, which invoke the corresponding cell method.
Notes
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, NSToken
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 token
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.