简体   繁体   中英

Accessing iPhone built-in dictionary or spell checker?

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!

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.

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

-(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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM