Skip to content

Instantly share code, notes, and snippets.

@omz
Created March 10, 2016 17:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omz/599ef8aeae22620261c6 to your computer and use it in GitHub Desktop.
Save omz/599ef8aeae22620261c6 to your computer and use it in GitHub Desktop.
Check dictionary word.py
# 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