1

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!

Matt N.
  • 1,239
  • 2
  • 11
  • 26
  • 1
    Duplicate of http://stackoverflow.com/questions/6861161/iphone-objective-c-detecting-a-real-word/6861260#6861260 See there for an implementation. – Jano Aug 07 '11 at 16:29
  • Yes, indeed. Can you post this comment as an answer? I'll accept it. Thank you! – Matt N. Aug 08 '11 at 08:27
  • @Matt:whats wrong with my answer? – VenoMKO Aug 08 '11 at 08:46
  • Nothing but the link he posted contains the code already written while your answer is a hint. So the link he posted is more useful. I gave you a vote, don't worry! – Matt N. Aug 08 '11 at 08:50

2 Answers2

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.

VenoMKO
  • 3,294
  • 32
  • 38
2

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;

}
Community
  • 1
  • 1
Jano
  • 62,815
  • 21
  • 164
  • 192