I have implemented NSTokenField with autocompletion using its delegate method:
- (NSArray *)tokenField:(NSTokenField *)tokenField
completionsForSubstring:(NSString *)substring
indexOfToken:(NSInteger)tokenIndex
indexOfSelectedItem:(NSInteger *)selectedIndex
{
return @[@"Token 1", @"Token 2", @"Token 3"];
}
...and it works pretty well with hardcoded array or any array that can be created locally in my application. I need the tokens to be downloaded from server as the user types in the token field. I am using AFNetworking 2 to get tokens for given substring asynchronously. Unfortunately I couldn't find a way to implement autocompletion with async flow. I have noticed that delegate method will freeze UI if it takes too long to return the completions array, so synchronous request to the server from this point is not a solution. Documentation also didn't get me a hint how to implement autocompletion asynchronously. Perhaps it needs some more complex solution that just using NSTextField
delegate method. Any help would be appreciated.