---
title: "tokenField(_:shouldAdd:at:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstokenfielddelegate/tokenfield(_:shouldadd:at:)"
---

# tokenField(_:shouldAdd:at:)

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

## Declaration

```swift
@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

Return Value An array of validated tokens.

## Discussion

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.

## See Also

### Editing a Tokenized Strings

- [tokenField(_:completionsForSubstring:indexOfToken:indexOfSelectedItem:)](appkit/nstokenfielddelegate/tokenfield(_:completionsforsubstring:indexoftoken:indexofselecteditem:).md)
- [tokenField(_:editingStringForRepresentedObject:)](appkit/nstokenfielddelegate/tokenfield(_:editingstringforrepresentedobject:).md)
- [tokenField(_:representedObjectForEditing:)](appkit/nstokenfielddelegate/tokenfield(_:representedobjectforediting:).md)
