访问iPhone内置字典或拼写检查?

时间:2021-07-21 17:28:21

In a game I have a text field where a user can enter a word. Now I'm trying to find a way to check whether the entered word is actually a word.

在游戏中,我有一个文本字段,用户可以在其中输入单词。现在我正试图找到一种方法来检查输入的单词是否实际上是一个单词。

Do you know if there is an interface to access the built-in dictionary? Or any other ideas apart from building my own word lists?

你知道是否有访问内置字典的界面?或者除了建立我自己的单词列表之外的任何其他想法?

Many thanks for your help!

非常感谢您的帮助!

2 个解决方案

#1


2  

Duplicate of iPhone objective-c: detecting a 'real' word, code posted by user brain:

重复的iPhone目标-c:检测“真实”字样,用户大脑发布的代码:

-(BOOL)isDictionaryWord:(NSString*)word {
    UITextChecker *checker = [[UITextChecker alloc] init];
    NSLocale *currentLocale = [NSLocale currentLocale];
    NSString *currentLanguage = [currentLocale objectForKey:NSLocaleLanguageCode];
    NSRange searchRange = NSMakeRange(0, [word size]];

    NSRange misspelledRange = [checker rangeOfMisspelledWordInString:word range: searchRange startingAt:0 wrap:NO language: currentLanguage ];
    return misspelledRange.location == NSNotFound;

}

#2


5  

I guess UITextChecker is what u looking for. You can use its rangeOfMisspelledWordInString:range:startingAt:wrap:language: method to detect whether entered string is a word or not.

我想UITextChecker就是你要找的东西。您可以使用其rangeOfMisspelledWordInString:range:startingAt:wrap:language:方法来检测输入的字符串是否为单词。

#1


2  

Duplicate of iPhone objective-c: detecting a 'real' word, code posted by user brain:

重复的iPhone目标-c:检测“真实”字样,用户大脑发布的代码:

-(BOOL)isDictionaryWord:(NSString*)word {
    UITextChecker *checker = [[UITextChecker alloc] init];
    NSLocale *currentLocale = [NSLocale currentLocale];
    NSString *currentLanguage = [currentLocale objectForKey:NSLocaleLanguageCode];
    NSRange searchRange = NSMakeRange(0, [word size]];

    NSRange misspelledRange = [checker rangeOfMisspelledWordInString:word range: searchRange startingAt:0 wrap:NO language: currentLanguage ];
    return misspelledRange.location == NSNotFound;

}

#2


5  

I guess UITextChecker is what u looking for. You can use its rangeOfMisspelledWordInString:range:startingAt:wrap:language: method to detect whether entered string is a word or not.

我想UITextChecker就是你要找的东西。您可以使用其rangeOfMisspelledWordInString:range:startingAt:wrap:language:方法来检测输入的字符串是否为单词。