Skip to content

Instantly share code, notes, and snippets.

@angry-boss
Forked from omz/Check dictionary word.py
Created November 16, 2025 11:17
Show Gist options
  • Select an option

  • Save angry-boss/0a91aa692ebeb3864977a51f5d934fd1 to your computer and use it in GitHub Desktop.

Select an option

Save angry-boss/0a91aa692ebeb3864977a51f5d934fd1 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