title: NSTextField autocomplete
body: <p>Does anyone know of any class or lib that can implement autocompletion to an NSTextField? </p>
  
  <p>I'am trying to get the standard autocmpletion to work but it is made as a synchronous api. I get my autocompletion words via an api call over the internet.</p>
  
  <p>What have i done so far is:</p>
  
  <pre><code>- (void)controlTextDidChange:(NSNotification *)obj
  {
      if([obj object] == self.searchField)
      {
          [self.spinner startAnimation:nil];
          [self.wordcompletionStore completeString:self.searchField.stringValue];
  
          if(self.doingAutocomplete)
              return;
          else
          {
              self.doingAutocomplete = YES;
              [[[obj userInfo] objectForKey:@"NSFieldEditor"] complete:nil];
          }
      }
  }
  </code></pre>
  
  <p>When my store is done, i have a delegate that gets called:</p>
  
  <pre><code>- (void) completionStore:(WordcompletionStore *)store didFinishWithWords:(NSArray *)arrayOfWords
  {
      [self.spinner stopAnimation:nil];
      self.completions = arrayOfWords;
      self.doingAutocomplete = NO;
  }
  </code></pre>
  
  <p>The code that returns the completion list to the nstextfield is:</p>
  
  <pre><code>- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index
  {
      *index = -1;
      return self.completions;
  }
  </code></pre>
  
  <p>My problem is that this will always be 1 request behind and the completion list only shows on every 2nd char the user inputs.</p>
  
  <p>I have tried searching google and SO like a mad man but i cant seem to find any solutions..</p>
  
  <p>Any help is much appreciated.</p>