Skip to content

Instantly share code, notes, and snippets.

@wgaylord
Forked from omz/Spellcheck word.py
Created March 22, 2016 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgaylord/6142b9da618b919f3fc2 to your computer and use it in GitHub Desktop.
Save wgaylord/6142b9da618b919f3fc2 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