Is there a way for UITextChecker to suggest learned words?

I would like to add words to the Apple dictionary used by UITextChecker and I know the learnWords: method. This documentation and my experience with it suggest that it only serves to ignore the words that are being learned. What I would like, and what seems obvious, would be to learn the words also provided in the guesses and tweaks provided by UITextChecker. Is it 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);
}

      

The user can enter "xyj" in the search box, which will run this code:

// 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!");
    }
}

      

+3


source to share





All Articles