Skip to content

Instantly share code, notes, and snippets.

@omz
Created March 10, 2016 20:01
Show Gist options
  • Save omz/e141f676504b743dbaa8 to your computer and use it in GitHub Desktop.
Save omz/e141f676504b743dbaa8 to your computer and use it in GitHub Desktop.
Spellcheck word.py
# coding: utf-8
from objc_util import ObjCClass
UITextChecker = ObjCClass('UITextChecker')
def check_word(word, lang='en_US'):
c = UITextChecker.new().autorelease()
check = c.rangeOfMisspelledWordInString_range_startingAt_wrap_language_
misspelled_range = check(word, (0, len(word)), 0, False, lang)
return (misspelled_range.location != 0)
test_words = ['foo', 'bar', 'baz', 'quuz', 'cat', 'dog']
for word in test_words:
print '%s: %s' % (word, check_word(word))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment