I have a button that adds a token to a NSTokenField. It adds the token always to the end of the field:
NSTokenField *currentField = [sender representedObject];
// Determine which token should be inserted into the field using the tag of the sender.
switch( [sender tag] )
{
case eFileNameToken_StartDate:
[currentField setObjectValue:[[currentField objectValue] arrayByAddingObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:kTokenName_StartDate, kTokenKey_Name, @"%m-%d-%Y", kTokenKey_Format, [NSNumber numberWithInt:0], kTokenKey_FormatIndex, nil]]];
break;
Because it is grabbing the array from the currentField objectValue and then creating an array by adding the object.
I would love to have it know the insertion point of the cursor and insert the object into the resulting currentField objectValue so that I can then setObjectValue of the currentField with the correctly ordered tokens. Thanks for any help yall