让UITextChecker建议学习单词的方法?

时间:2015-01-08 20:37:53

标签: ios objective-c autocorrect uitextchecker

我想在UITextChecker使用的Apple Dictionary中添加单词,我知道learnWords:方法。它的文档以及我对它的体验表明,它只会忽略所学的单词。我想要的,以及看似显而易见的是,UITextChecker提供的猜测和完成也提供了学习单词。这可能吗?

这是我开始的代码:

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

用户可能会输入" xyj"进入搜索字段,这将提示此代码运行:

// 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 个答案:

没有答案