---
title: "tokenFieldCell(_:shouldAdd:at:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstokenfieldcelldelegate/tokenfieldcell(_:shouldadd:at:)"
---

# tokenFieldCell(_:shouldAdd:at:)

Allows the delegate to validate the tokens to be added to the receiver at a given index.

## Declaration

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

## Parameters

- `tokenFieldCell`: The token field cell 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

- [tokenFieldCell(_:completionsForSubstring:indexOfToken:indexOfSelectedItem:)](appkit/nstokenfieldcelldelegate/tokenfieldcell(_:completionsforsubstring:indexoftoken:indexofselecteditem:).md)
- [tokenFieldCell(_:editingStringForRepresentedObject:)](appkit/nstokenfieldcelldelegate/tokenfieldcell(_:editingstringforrepresentedobject:).md)
- [tokenFieldCell(_:representedObjectForEditing:)](appkit/nstokenfieldcelldelegate/tokenfieldcell(_:representedobjectforediting:).md)
