Way to have UITextChecker suggest learned words?

573 views Asked by At

I would like to add words to the Apple Dictionary used by UITextChecker, and I am aware of the learnWords: method. It's documentation, and my experience with it, suggest that it only serves to ignore words that are learned. What I would like, and what seems obvious, would be to have learned words also provided as guesses and completions provided by the UITextChecker. Is that possible?

Here's the code I'm starting with:

NSString *newWord = [NSString stringWithFormat:@"%@", @"xyz"];
if ([UITextChecker hasLearnedWord:newWord]) {
    NSLog(@"skipped %@", newWord);
} else {
    [UITextChecker learnWord:newWord];
    NSLog(@"learning %@", newWord);
}

A user might enter "xyj" into a search field, which would prompt this code to run:

// Fake User Input
NSString *word = @"xyj";

UITextChecker *checker = [[UITextChecker alloc] init];
NSRange range = NSMakeRange(0, word.length);
NSArray *guesses = [checker guessesForWordRange:range inString:word language:@"en_US"];
for (NSString *guess in guesses) {
    if ([guess isEqualToString:@"xyz"]) {
        NSLog(@"Success, iOS suggested xyz!");
    }
}
0

There are 0 answers