Access iOS dictionary programmatically
There is no API to do what you are asking.
There is an API for bringing up the built-in dictionary UI (not the original question but raised in some of the responses), including checking for whether a given word is defined:
if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:@"word"]) {
UIReferenceLibraryViewController* ref =
[[UIReferenceLibraryViewController alloc] initWithTerm:@"word"];
[currentViewController presentViewController:ref animated:YES completion:nil];
}
I don't think there is a public API to access the embedded Dictionary. The closest is using UITextChecker but that may not satisfy your needs
As an alternative, you could find and embed a Word Dictionary in the Language you want? It may require some extra work
There is no API, but if all you need is a list of words you can read it from /usr/share/dict/words
:
NSString *allTheWords = [NSString stringWithContentsOfFile: @"/usr/share/dict/words"
encoding: NSUTF8StringEncoding
error: nil];
for (NSString *line in [allTheWords componentsSeparatedByString:@"\n"]) {
NSLog(@"%@",line);
}
If you need an arbitrary list of words you can get it from several online resources, here is one. The README at /usr/share/dict/README says iOS word list uses ftp://ftp.ox.ac.uk/pub/wordlists
For instant search you'll need to load the words on a structure suitable for prefix search, like a trie. Here is a sample project where I did just that.
If you need a dictionary, get one online, then include a pointer to the word entry in the trie node. If loading takes too much time you can experiment loading on the background, or compressing, or serializing the trie.