开发者

Building a word game in iphone

I'm trying to build a word game in iphone. Basically, the user should be able to input a word to the screen using the keyboard(easy) and the app should be able to validat开发者_开发百科e the word and suggest some other similar words (search a dictionary perhaps).

Is there a built in word dictionary on iphone that I can use. Any guidance to get this started would be much appreciated.


There isn't a dictionary built in on the iphone as far as I can tell, but you can do one of the following:

  1. Download a big dictionary from the Internet (it'll come as just a text file), then ship it as a part of your application.
  2. Hit a web service that has a dictionary on the server side to look for matches.


I made an open source class called CDWordList which loads in a text file containing a list of words. You can see if a string is a word by calling -(BOOL)isWord:(NSString*)word on the object. The project comes with the English Open Word List (EOWL) which has about 128 thousand words.


I've published a static library called Lexicontext some time ago, which I think is relevant if you want to pursue the offline option (it's based on WordNet).


Old thread I know but UITextChecker does the first part without downloading wordlists:

-(BOOL)isDictionaryWord:(NSString*) word {
    UITextChecker *checker = [[UITextChecker alloc] init];
    NSLocale *currentLocale = [NSLocale currentLocale];
    NSString *currentLanguage = [currentLocale objectForKey:NSLocaleLanguageCode];
    NSRange searchRange = NSMakeRange(0, [word length]);    
    NSRange misspelledRange = [checker rangeOfMisspelledWordInString:[word lowercaseString] range: searchRange startingAt:0 wrap:NO language: currentLanguage ];
return misspelledRange.location == NSNotFound;
}

Got this from the stackoverflow link here: iPhone objective-c: detecting a 'real' word

I've tweaked the link code to change the string to lowercase, otherwise it always return a True for capital letters for some reason

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜