Is there a way to get spell check data using NSString?

I am writing an iPhone app with a simple shift as a pet project, and one part of the functionality I'm currently developing is the “universal” NSString decryption, which returns NSArray, all NSStrings:

- (NSArray*) decryptString: (NSString*)ciphertext{
NSMutableArray* theDecryptions = [NSMutableArray arrayWithCapacity:ALPHABET];

for (int i = 0; i < ALPHABET; ++i) {
    NSString* theNewPlainText = [self decryptString:ciphertext ForShift:i];

    [theDecryptions insertObject:theNewPlainText
                         atIndex:i];
}
return theDecryptions;

}

I would really like to pass this NSArray to another method, which tries to check each individual row in the array and creates a new array that puts the rows with the least number of typo'd words at lower rates, first displayed. I would like to use the system dictionary as a text field, so I can match the words that were trained on the phone by its user.

, , NSSpellChecker -checkSpellingOfString:StartingAt: . , ?

+5
1

, , UIKit/UITextChecker. , , rangeOfMisspelledWords.... , [UITextChecker hasLearnedWord] currentWord if , , .

, rangeOfMisspelledWords [UITextChecker availableLanguages], .

-(void) checkForDefinedWords {
    NSArray* words = [message componentsSeparatedByString:@" "];
    NSInteger wordsFound = 0;
    UITextChecker* checker = [[UITextChecker alloc] init];
    //get the first language in the checker memory- this is the user's
    //preferred language.
    //TODO: May want to search with every language (or top few) in the array
    NSString* preferredLang = [[UITextChecker availableLanguages] objectAtIndex:0];

    //for each word in the array, determine whether it is a valid word
    for(NSString* currentWord in words){
        NSRange range;
        range = [checker rangeOfMisspelledWordInString:currentWord
                                                 range:NSMakeRange(0, [currentWord length]) 
                                            startingAt:0 
                                                  wrap:NO
                                              language:preferredLang];

        //if it is valid (no errors found), increment wordsFound
        if (range.location == NSNotFound) {
            //NSLog(@"%@ %@", @"Valid Word found:", currentWord);
            wordsFound++;
        }
        else {
            //NSLog(@"%@ %@", @"Invalid Word found:", currentWord);
        }
    }


    //After all "words" have been searched, save wordsFound to validWordCount
    [self setValidWordCount:wordsFound];

    [checker release];
}
+2

All Articles