Created
March 10, 2016 17:36
-
-
Save omz/599ef8aeae22620261c6 to your computer and use it in GitHub Desktop.
Check dictionary word.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
''' | |
Demo of using the built-in iOS dictionary to check words | |
NOTES: This is quite slow, it might be possible to use the spell-checking | |
dictionary for this instead, haven't tried that yet. | |
If no dictionary is downloaded yet, the API will always return True | |
(probably so that the "Define" menu item can be shown before | |
a dictionary has been downloaded). | |
''' | |
from objc_util import ObjCClass | |
def is_word_valid(word): | |
reflib = ObjCClass('UIReferenceLibraryViewController') | |
return reflib.dictionaryHasDefinitionForTerm_(word) | |
test_words = ['foo', 'bar', 'quuz', 'cat', 'dog'] | |
for word in test_words: | |
print '%s: %s' % (word, is_word_valid(word)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment