NSTokenField - How To Tell If I'm Editing an Existing Token in -tokenField:representedObjectForEditingString: ?

I'm trying to use NSTokenField for the first time.

So my custom 'representedObject' for a token has additional model data tied to it (not just the editing/display string). I noticed when I edit an existing token, type text, and hit the enter key I get the following delegate callback:

- (nullable id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString:(NSString *)editingString;


This same delegate method is called when I type a brand new token. Is there a way to distinguish if I'm editing a token vs. creating a new one?

My expectation is to be able to do something like this (made up enhancement):

- (nullable id)tokenField:(NSTokenField *)tokenField 
representedObjectForEditingString:(NSString *)editingString 
atIndex:(NSUInteger)existingTokenIndex
{
	if (existingTokenIndex == NSNotFound)
	{
		// Token is new, create a new instance
		MyTokenObject *newToken = //create and configure.
		return newToken;
	}
	else 
    {
		// This would update the editing string but wouldn't discard existing data held by the token.
		MyTokenObject *tokenObj = [self existingTokenAtIndex:existingTokenIndex];
		tokenObj.editingString = editingString;
		return tokenObj;
	}
}
NSTokenField - How To Tell If I'm Editing an Existing Token in -tokenField:representedObjectForEditingString: ?
 
 
Q