<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTokenFieldDelegate/tokenField(_:shouldAdd:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTokenFieldDelegate(im)tokenField:shouldAddObjects:atIndex:"
  },
  "title" : "tokenField(_:shouldAdd:at:)"
}
-->

# tokenField(_:shouldAdd:at:)

Allows the delegate to validate the tokens to be added to the receiver at a particular location.

```
@MainActor optional func tokenField(_ tokenField: NSTokenField, shouldAdd tokens: [Any], at index: Int) -> [Any]
```

## Parameters

`tokenField`

The token field that sent the message.

`tokens`

An array of tokens to be inserted in the receiver at `index`.

`index`

The index of the receiver in which the array of tokens to be validated (`tokens`) will be inserted.

## Return Value

An array of validated tokens.

## Discussion

The delegate can return the array unchanged or return a modified array of tokens. To reject the add completely, return an empty array. Returning `nil` causes an error.

---

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)