새 사전을 추가하지 않고도 UITextChecker가 정확하게 작동하도록 만들 수 있습니다.
빠른 (정확하지는 않지만) 첫 번째 단계가 필요하기 때문에 2 단계 프로세스를 사용합니다. 정확한 수표 인 2 단계 만 필요할 수 있습니다. 이것은 UITextChecker의 completionsForPartialWordRange 함수를 사용하므로 MisspelledWord 함수보다 정확합니다.
// 1 단계 : 문자 조합이 맞춤법 검사를 통과하는지 신속하게 확인합니다. 이것은 정확하지 않지만 속도가 매우 빠르므로 많은 문자 조합을 신속하게 제외 할 수 있습니다 (무차별 대입 방식).
UITextChecker *checker;
NSString *wordToCheck = @"whatever"; // The combination of letters you wish to check
// Set the range to the length of the word
NSRange range = NSMakeRange(0, wordToCheck.length - 1);
NSRange misspelledRange = [checker rangeOfMisspelledWordInString:wordToCheck range: range startingAt:0 wrap:NO language: @"en_US"];
BOOL isRealWord = misspelledRange.location == NSNotFound;
// Call step two, to confirm that this is a real word
if (isRealWord) {
isRealWord = [self isRealWordOK:wordToCheck];
}
return isRealWord; // if true then we found a real word, if not move to next combination of letters
// 2 단계 : 단어가 실제 단어인지 확인하기위한 추가 검사. 실제 단어가 있으면 true를 반환합니다.
-(BOOL)isRealWordOK:(NSString *)wordToCheck {
// we dont want to use any words that the lexicon has learned.
if ([UITextChecker hasLearnedWord:wordToCheck]) {
return NO;
}
// now we are going to use the word completion function to see if this word really exists, by removing the final letter and then asking auto complete to complete the word, then look through all the results and if its not found then its not a real word. Note the auto complete is very acurate unlike the spell checker.
NSRange range = NSMakeRange(0, wordToCheck.length - 1);
NSArray *guesses = [checker completionsForPartialWordRange:range inString:wordToCheck language:@"en_US"];
// confirm that the word is found in the auto-complete list
for (NSString *guess in guesses) {
if ([guess isEqualToString:wordToCheck]) {
// we found the word in the auto complete list so it's real :-)
return YES;
}
}
// if we get to here then it's not a real word :-(
NSLog(@"Word not found in second dictionary check:%@",wordToCheck);
return NO;
}
n NSSpellChecker를 사용하지 않는 이유는 무엇입니까? – Goz
@Wolfgang : NSObject NSString과 같습니다. – brain
@Wolfgang : NS 접두어를 사용하는 클래스는 NSObject, NSNumber, NSString, NSPredicate, NSFetchedController 등과 같이 iOS에서 사용할 수 있습니다. – rckoenes