UITextChecker Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 3.2 and later.
Declared in
UITextChecker.h

Overview

You use instances of the UITextChecker class to check a string (usually the text of a document) for misspelled words.

UITextChecker spell-checks using a lexicon for a given language. You can tell it to ignore specific words when spell-checking a particular document and you can have it learn words, which adds those words to the lexicon. You generally use one instance of UITextChecker per document, although you can use a single instance to spell-check related pieces of text if you want to share ignored words and other state.

You may also use UITextChecker to obtain completions for partially entered words, as well as possible replacements for misspelled words, which you then can present to users.

Tasks

Initiating a Spell Check

Obtaining Word Guesses and Completions

Learning and Ignoring Words

Getting the Available Languages

Class Methods

availableLanguages

Returns the languages for which the text checker’s class can perform spell-checking.

+ (NSArray *)availableLanguages
Return Value

An array of strings representing ISO 639-1 language codes or combined ISO 639-1 language codes and ISO 3166-1 regional codes (for example, en_US).

Discussion

The languages represented by the strings in the returned array are in user-preference order.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

hasLearnedWord:

Returns whether the text checker has learned the specified word.

+ (BOOL)hasLearnedWord:(NSString *)word
Parameters
word

A string representing a word.

Return Value

YES if the class has learned the word, otherwise NO.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

learnWord:

Tells the text checker to learn the specified word so that it is not evaluated as misspelled.

+ (void)learnWord:(NSString *)word
Parameters
word

A string representing the word for the class to learn.

Discussion

When a UITextChecker object learns a word, it is added to the dictionary. It is global across languages.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

unlearnWord:

Tells the text checker to unlearn the specified word

+ (void)unlearnWord:(NSString *)word
Parameters
word

A string representing the word for the class to unlearn.

Discussion

When a UITextChecker object unlearns a word, it is removed from the dictionary.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

Instance Methods

completionsForPartialWordRange:inString:language:

Returns an array of strings that are possible completions for a partially entered word.

- (NSArray *)completionsForPartialWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language
Parameters
range

The range of a partially entered word in string.

string

A string in which there is a partially entered word, as located by range.

language

The language of the of the words that are possible corrections. This string is a ISO 639-1 language code or a combined ISO 639-1 language code and ISO 3166-1 regional code (for example, fr_CA).

Return Value

An array of strings, each of which is a completion of a partially entered word represented by range in string. If no possible completions are found, the method returns an empty array.

Discussion

The strings in the array are in the order they should be presented to the user—that is, more probable completions come first in the array.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

guessesForWordRange:inString:language:

Returns a list of words that are possible valid replacements for a misspelled word.

- (NSArray *)guessesForWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language
Parameters
range

The range of a misspelled word in string.

string

A string in which there is a misspelled word, as located by range.

language

The language of the of the words that are possible corrections. This string is from the ISO 639-1 standard, for example es (Spanish).

Return Value

An array of strings each of which might be a correct substitute (that is, a guess) for a misspelled word in the given range of the string. If no possible guesses are found, the method returns an empty array.

Discussion

The strings in the array are in the order they should be presented to the user—that is, more probable guesses come first in the array.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

ignoredWords

Returns the words that the receiver ignores when spell-checking.

- (NSArray *)ignoredWords
Return Value

An array of strings, each of which specifies a word the receiver ignores when it is spell-checking a document.

Discussion

The spell checker excludes ignored words as misspelled words during the current spell-checking session only.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

ignoreWord:

Tells the receiver to ignore the specified word when spell-checking.

- (void)ignoreWord:(NSString *)wordToIgnore
Parameters
wordToIgnore

A string that is a word the receiver should ignore when it is spell-checking a document.

Discussion

The spell checker excludes ignored words as misspelled words during the current spell-checking session only.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

rangeOfMisspelledWordInString:range:startingAt:wrap:language:

Initiates a search of a range of a string for a misspelled word.

- (NSRange)rangeOfMisspelledWordInString:(NSString *)stringToCheck range:(NSRange)range startingAt:(NSInteger)startingOffset wrap:(BOOL)wrapFlag language:(NSString *)language
Parameters
stringToCheck

The string to check for misspelled words.

range

The range of stringToCheck to check for a misspelled word.

startingOffset

The offset within range of stringToCheck to begin checking for misspelled words.

wrapFlag

YES to continue checking from the beginning of range if no misspelled word is found between startingOffset and the end of range. Specify NO to have spell-checking end at the end of range.

language

The language of the of words to be checked for correct spelling. This string is a ISO 639-1 language code or a combined ISO 639-1 language code and ISO 3166-1 regional code (for example, fr_FR).

Return Value

The range of the first misspelled word encountered or {NSNotFound, 0} if none is found.

Discussion

To search an entire string or a range within that string, call this method in a loop, resetting startingOffset from each returned range, until you reach the end of the string or specified range within the string.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h

setIgnoredWords:

Sets the list of words that the receiver should ignore when it is spell-checking a document.

- (void)setIgnoredWords:(NSArray *)words
Parameters
words

An array of strings, each of which specifies a word the receiver should ignore when it is spell-checking a document.

Discussion

Ignored words are not treated as misspelled words only for the current spell-checking session.

Availability
  • Available in iOS 3.2 and later.
Declared In
UITextChecker.h