iOS Developer Library

Developer

UIKit Framework Reference UITextChecker Class Reference

Options
Deployment Target:

On This Page
Language:

UITextChecker

Inherits From


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 3.2 and later

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.

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

    Declaration

    Swift

    func rangeOfMisspelledWordInString(_ stringToCheck: String!, range range: NSRange, startingAt startingOffset: Int, wrap wrapFlag: Bool, language language: String) -> NSRange

    Objective-C

    - (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

    YEStrue to continue checking from the beginning of range if no misspelled word is found between startingOffset and the end of range. Specify NOfalse 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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

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

    Declaration

    Swift

    func guessesForWordRange(_ range: NSRange, inString string: String, language language: String) -> [AnyObject]?

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

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

    Declaration

    Swift

    func completionsForPartialWordRange(_ range: NSRange, inString string: String?, language language: String) -> [AnyObject]?

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

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

    Declaration

    Swift

    func ignoreWord(_ wordToIgnore: String)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

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

    Declaration

    Swift

    func ignoredWords() -> [AnyObject]!

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

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

    Declaration

    Swift

    func setIgnoredWords(_ words: [AnyObject]!)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

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

    Declaration

    Swift

    class func learnWord(_ word: String!)

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

  • Tells the text checker to unlearn the specified word

    Declaration

    Swift

    class func unlearnWord(_ word: String)

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

  • Returns whether the text checker has learned the specified word.

    Declaration

    Swift

    class func hasLearnedWord(_ word: String) -> Bool

    Objective-C

    + (BOOL)hasLearnedWord:(NSString *)word

    Parameters

    word

    A string representing a word.

    Return Value

    YEStrue if the class has learned the word, otherwise NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later

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

    Declaration

    Swift

    class func availableLanguages() -> [AnyObject]

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later