UITextChecker: Way to Check If Word is Already Correct?

835 views Asked by At

UITextChecker' rangeOfMisspelledWordInString:range:startingAt:wrap:language: returns nil if no correction is found. However I was wondering if there's a way to tell if no correction was found because A. It's already correct or B. Nothing Exists for the current word.

This is what I have right now:

if (!arrayOfPossibleCorrections || !arrayOfPossibleCorrections.count) {
    //If nothing found bc it's already correct leave it alone
    //Else dosomething
} else {
    //Replace currentWord with correctWord
}
1

There are 1 answers

1
ForguesR On BEST ANSWER

From Apple developer library, rangeOfMisspelledWordInString returns {NSNotFound, 0} if no misspelled word is found which is exactly what you are asking for.

It is guessesForWordRange that will return an empty array if no correction is found.

In short you should call guessesForWordRange only when there is a misspelled word range returned by rangeOfMisspelledWordInString.