NSSpellChecker

The NSSpellChecker class provides an interface to the Cocoa spell-checking service. To handle all its spell checking, an application needs only one instance of NSSpellChecker, known as the spell checker. Through the spell checker you manage the Spelling panel, in which the user can specify decisions about words that are suspect.
More...

The spell checker also offers the ability to provide word completions to augment the text completion system in OS X v10.3.

Declaration

Parameters

aView

The accessory view displayed in the receiver.

Discussion

The accessory view can be any custom view you want to display with the spelling panel. The accessory view is displayed below the spelling checker and the panel automatically resizes to accommodate the accessory view.

Declaration

Parameters

accessoryController

The accessory view controller or nil if there is none.

Discussion

The accessory view controller can accommodate any custom view you want to display with the substitutions panel. The accessory view controller’s view is displayed below the substitutions list and the panel automatically resizes to accommodate the accessory view.

Parameters

stringToCheck

The string object containing the words to spellcheck.

startingOffset

The offset within stringToCheck at which to begin spellchecking.

language

The language of the words in the string. If language is nil, or if you obtain the value by sending language to self, the current selection in the Spelling panel’s pop-up menu is used. Do not pass in an empty string for language.

wrapFlag

YEStrue to indicate that spell checking should continue at the beginning of the string when the end of the string is reached; NOfalse to indicate that spellchecking should stop at the end of the document.

tag

An identifier unique within the application used to inform the spell checker which document that text is associated, potentially for many purposes, not necessarily just for ignored words. A value of 0 can be passed in for text not associated with a particular document.

wordCount

Returns by indirection a count of the words spell-checked up to and including the first error (if any), or -1 if the spell checker fails or does not support word counting. Specify NULL if you do not want this word count.

Return Value

The range of the first misspelled word and optionally (and by reference) the count of words spellchecked in the string in wordCount.

Parameters

Language use in string. When nil, the language selected in the Spelling panel is used.

wrap

YEStrue to specify that the analysis continue to the beginning of string when the end is reached.

NOfalse to have the analysis stop at the end of string.

documentTag

An identifier unique within the application used to inform the spell checker which document that text is associated, potentially for many purposes, not necessarily just for ignored words. A value of 0 can be passed in for text not associated with a particular document.

outDetails

On output, dictionaries describing grammar-analysis details within the flagged grammatical unit. See the NSSpellServer class for information about these dictionaries.

An identifier unique within the application used to inform the spell checker which document that text is associated, potentially for many purposes, not necessarily just for ignored words. A value of 0 can be passed in for text not associated with a particular document.

orthography

Returns by-reference, the orthography of the range of the string. See NSOrthography for more information.

wordCount

Returns by-reference, the word count for the range of the string.

Return Value

An array of NSTextCheckingResult objects describing particular items found during checking and their individual ranges, sorted by range origin, then range end, then result type.

An identifier unique within the application used to inform the spell checker which document that text is associated, potentially for many purposes, not necessarily just for ignored words. A value of 0 can be passed in for text not associated with a particular document.

completionHandler

The completion handler block object will be called (in an arbitrary context) when results are available, with the sequence number and results.

The block takes four arguments:

sequenceNumber

A monotonically increasing sequence number.

results

An array of NSTextCheckingResult objects describing particular items found during checking and their individual ranges, sorted by range origin, then range end, then result type..

orthography

The orthography of the string.

wordCount

The number of words in the range of the string.

Return Value

The return value is a monotonically increasing sequence number that can be used to keep track of requests in flight.

Parameters

range

The range of the string to check.

string

The string to guess.

language

The language of the string.

tag

An identifier unique within the application used to inform the spell checker which document that text is associated, potentially for many purposes, not necessarily just for ignored words. A value of 0 can be passed in for text not associated with a particular document.

Declaration

Discussion

You are responsible for highlighting word in the document and for extracting it from the document using the range returned by the checkSpelling:... methods. Pass the empty string as word to have the system beep, indicating no misspelled words were found.

Parameters

range

The range of the word to be corrected.

string

The string containing the proposed correction.

language

The language.

tag

An identifier unique within the application used to inform the spell checker which document that text is associated, potentially for many purposes, not necessarily just for ignored words. A value of 0 can be passed in for text not associated with a particular document.

Return Value

The proposed correct string.

Special Considerations

While correction functionality is available starting in OS X v10.6 as part of unified text checking, for convenience this method makes it available separately starting in OS X v10.7.

Parameters

The first string to be displayed, a correction or reversion according to the type of indicator.

alternativeStrings

An array of alternative strings to insert. This array may be empty.

rectOfTypedString

The rectangle of the typed text.

view

The view in which the correction indicator is to be displayed.

completionBlock

The Block called when a the correction indicator is dismissed.

The Block takes one argument:

acceptedString

The correction string the user excepted. If the user does not select a correction string nil is returned.

Discussion

Only one indicator at a time may be displayed for a given view, and the only thing a client may do with the indicator after displaying it is to dismiss it using the dismissCorrectionIndicatorForView: method.

An identifier unique within the application used to inform the spell checker which document that text is associated, potentially for many purposes, not necessarily just for ignored words. A value of 0 can be passed in for text not associated with a particular document.

Discussion

When a correction is automatically proposed, the user may respond in one of several ways. Clients may report this to the spell checker so that it can learn from the user's response and adjust future correction behavior accordingly.

Note

Use of this method implies that the client stored the original word and original correction at least from the point at which the user accepts it until the user edits or reverts it.

Constants

An NSOrthography instance indicating an orthography to be used as a starting point for orthography checking, or as the orthography if orthography checking is not enabled.

Available in OS X v10.6 and later.

NSTextCheckingQuotesKey

NSTextCheckingQuotesKey

An NSArray containing four strings to be used with NSTextCheckingTypeQuote (opening double quote, closing double quote, opening single quote, and closing single quote in that order); if not specified, values will be taken from user's preferences.

Available in OS X v10.6 and later.

NSTextCheckingReplacementsKey

NSTextCheckingReplacementsKey

An NSDictionary containing replacements to be used with NSTextCheckingTypeReplacement; if not specified, values will be taken from user's preferences.

Available in OS X v10.6 and later.

NSTextCheckingReferenceDateKey

NSTextCheckingReferenceDateKey

An NSDate to be associated with the document, used as a referent for relative dates; if not specified, the current date will be used.

Available in OS X v10.6 and later.

NSTextCheckingReferenceTimeZoneKey

NSTextCheckingReferenceTimeZoneKey

An NSTimeZone to be associated with the document, used as a reference for dates without time zones; if not specified, the current time zone will be used.

Available in OS X v10.6 and later.

NSTextCheckingDocumentURLKey

NSTextCheckingDocumentURLKey

An NSURL to be associated with the document.

Available in OS X v10.6 and later.

NSTextCheckingDocumentTitleKey

NSTextCheckingDocumentTitleKey

An NSString containing the title to be associated with the document.

Available in OS X v10.6 and later.

NSTextCheckingDocumentAuthorKey

NSTextCheckingDocumentAuthorKey

An NSString containing the name of an author to be associated with the document