March 2014
Intermediate to advanced
672 pages
40h 11m
English
Using UITextChecker, you can add a handy little protocol to NSString for checking the spelling correctness of any string (see Listing 6-1).
Listing 6-1 Spell Checker Protocol
@implementation NSString (SpellCheck) - (BOOL)isSpelledCorrectly { UITextChecker *checker = [[UITextChecker alloc] init]; NSRange checkRange = NSMakeRange(0, self.length); NSString *language = [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]; NSRange range = [checker rangeOfMisspelledWordInString:self range:checkRange startingAt:0 wrap:NO language:language]; return (range.location == NSNotFound); } @end
Read now
Unlock full access