Search code examples
objective-cxcode4spell-checking

UITextChecker without proper nouns


I'm exercising the UITextChecker class to do a quick check on a string for a word-spelling game. Works a little TOO well. Unfortunately, as far as I can tell, the only methods that operate on this class return "correct" words that also include proper nouns. I would like to check my strings against a list of common words that do NOT include proper nouns. Here's my code so far:

    //Test the answer for a word
    UITextChecker *checker = [[UITextChecker alloc] init];
    NSString *testString = wordString;
    NSRange range = NSMakeRange(0,0);
    range = [checker rangeOfMisspelledWordInString:[testString lowercaseString] 
                                             range:NSMakeRange(0, [testString length]) 
                                        startingAt:0 
                                              wrap:NO 
                                          language:@"en_US"];
    if (range.location == NSNotFound) {
        spelledWord = YES;

    } else {
        spelledWord = NO;

    }

Any help would be appreciated!


Solution

  • Not sure if this is the easiest way but you could put a second condition. First store an array with proper nouns (or other words you don't want) elsewhere in your code do a search on Google if you can't think of them. (I've adapted this slightly from a method i use)

    if (range.location == NSNotFound) {
    int i = 1;
    NSString *p;
    foundrand = FALSE;
    if ([[MyArray sharedKelArray].Myarray count] >2){
            ////NSLog(@"GOTTEN - %d", choosennumber);
            while(i<[[MyArray sharedKelArray].Myarray count])//would check that if equal
            {
                p = [[[MyArray sharedKelArray].Myarray objectAtIndex:i] NSString];
                NSLog(@"Checking word - %d",p);
    
    
    
                   if (testString == p){
                        NSLog(@"Matched");
                        spelledWord = NO;
    i = 5 + [[MyArray sharedKelArray].Myarray count];
    
                    }
                    i+=1;
    
            }
            spelledWord = YES;
        }
    }
    
    }