NSFieldEditor / NSTextView: set Dictionary for autocomplete

96 Views Asked by At

I invoke autocomplete on a NSTextField by using it's field editor:

-(void)controlTextDidChange:(NSNotification *)notification {

    NSTextView *fieldEditor = [[notification userInfo] objectForKey:@"NSFieldEditor"];
    NSString *newValue = [fieldEditor string];
    BOOL textDidNotChange = [lastTypedStreetValue isEqualToString:newValue];

    if( textDidNotChange ){
        return;
    }
    else {
        lastTypedStreetValue = [newValue copy];    
        [fieldEditor complete:nil];
    }
}

How do I set the dictionary for the autocomplete of this NSTextField?

= How do I set the words that pop up as suggestions in the autocomplete?

I have an NSArray of words I need to use.

1

There are 1 best solutions below

0
murkr On

Thank you @Willeke, the solution looks as follows:

 -(NSArray *)  control:(NSControl*) control
              textView:(NSTextView*) textView
           completions:(NSArray*) words
   forPartialWordRange:(NSRange) charRange
   indexOfSelectedItem:(NSInteger*) index
{
    NSArray *array = [methodThatCreatesTheWordList];
    return array;
}