NSSpellServerDelegate Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.6 and later.
Companion guide
Declared in
NSSpellServer.h

Overview

The NSSpellServerDelegate protocol defines the optional methods implemented by delegates of NSSpellServer objects.

Tasks

Check Grammar and Spelling in Strings

Managing the Spelling Dictionary

Instance Methods

spellServer:checkGrammarInString:language:details:

Gives the delegate the opportunity to customize the grammatical analysis of a given string.

- (NSRange)spellServer:(NSSpellServer *)sender checkGrammarInString:(NSString *)string language:(NSString *)language details:(NSArray **)outDetails
Parameters
sender

Spell server satisfying a grammatical analysis request.

string

String to analyze.

language

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

outDetails

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

Return Value

Location of the first flagged grammatical unit within string.

Availability
  • Available in OS X v10.5 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSSpellServer.h

spellServer:checkString:offset:types:options:orthography:wordCount:

Gives the delegate the opportunity to analyze both the spelling and grammar simultaneously, which is more efficient.

- (NSArray *)spellServer:(NSSpellServer *)sender checkString:(NSString *)stringToCheck offset:(NSUInteger)offset types:(NSTextCheckingTypes)checkingTypes options:(NSDictionary *)options orthography:(NSOrthography *)orthography wordCount:(NSInteger *)wordCount
Parameters
sender

Spell server making the analysis request.

stringToCheck

String to analyze.

offset

The offset in the string.

checkingTypes

The text checking types to perform.

options

A dictionary defining the actions to be taken while checking this string. See Constants in NSSpellChecker for the possible keys.

orthography

The identified orthography of stringToCheck. See NSOrthography for more information.

wordCount

On output, returns by-reference the number of words from the beginning of the string object until the misspelled word (or the end of string).

Return Value

An array of NSTextCheckingResult instances of the spelling, grammar, or correction types, depending on the checkingTypes requested.

Discussion

This method is optional, but if implemented it will be called during the course of unified text checking via the NSSpellChecker checkSpellingOfString:startingAt: and requestCheckingOfString:range:types:options:inSpellDocumentWithTag:completionHandler: methods. This allows spelling and grammar checking to be performed simultaneously, which can be significantly more efficient, and allows the delegate to return autocorrection results as well.

If this method is not implemented, then unified text checking will call the separate spelling and grammar checking methods instead.

This method may be called repeatedly with strings representing different subranges of the string that was originally requested to be checked; the offset argument represents the offset of the portion passed in to this method within that original string, and should be added to the origin of the range in any NSTextCheckingResult returned.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSSpellServer.h

spellServer:didForgetWord:inLanguage:

Notifies the delegate that the sender has removed the specified word from the user’s list of acceptable words in the specified language.

- (void)spellServer:(NSSpellServer *)sender didForgetWord:(NSString *)word inLanguage:(NSString *)language
Parameters
sender

The NSSpellServer object that removed the word.

word

The word that was removed.

language

The language of the removed word.

Discussion

If your delegate maintains a similar auxiliary word list, you may wish to edit the list accordingly.

Availability
  • Available in OS X v10.0 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSSpellServer.h

spellServer:didLearnWord:inLanguage:

Notifies the delegate that the sender has added the specified word to the user’s list of acceptable words in the specified language.

- (void)spellServer:(NSSpellServer *)sender didLearnWord:(NSString *)word inLanguage:(NSString *)language
Parameters
sender

The NSSpellServer object that added the word.

word

The word that was added.

language

The language of the added word.

Discussion

If your delegate maintains a similar auxiliary word list, you may wish to edit the list accordingly.

Availability
  • Available in OS X v10.0 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSSpellServer.h

spellServer:findMisspelledWordInString:language:wordCount:countOnly:

Asks the delegate to search for a misspelled word in a given string, using the specified language, and marking the first misspelled word found by returning its range within the string.

- (NSRange)spellServer:(NSSpellServer *)sender findMisspelledWordInString:(NSString *)stringToCheck language:(NSString *)language wordCount:(NSInteger *)wordCount countOnly:(BOOL)countOnly
Parameters
sender

The NSSpellServer object that sent this message.

stringToCheck

The string to search for the misspelled word.

language

The language to use for the search.

wordCount

On output, returns by reference the number of words from the beginning of the string object until the misspelled word (or the end of string).

countOnly

If YES, the method only counts the words in the string object and does not spell checking.

Return Value

The range of the misspelled word within the given string.

Discussion

Send isWordInUserDictionaries:caseSensitive: to the spelling server to determine if the word exists in the user’s language dictionaries.

Availability
  • Available in OS X v10.0 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSSpellServer.h

spellServer:recordResponse:toCorrection:forWord:language:

Notifies the spell checker of the users’s response to a correction. (required)

- (void)spellServer:(NSSpellServer *)sender recordResponse:(NSUInteger)response toCorrection:(NSString *)correction forWord:(NSString *)word language:(NSString *)language
Parameters
sender

The spell server.

response

The user’s response.

correction

The corrected word. This should match the original correction.

word

The original word. This should match the original correction.

language

The language being edited. This should match the original correction.

Discussion

When the user accepts, rejects, or edits an autocorrection, the view notifies the NSSpellChecker class of what happened in the client application, and NSSpellChecker then invokes this method, so that it can record that and modify future autocorrection behavior based on what it has learned from the user's actions.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSSpellServer.h

spellServer:suggestCompletionsForPartialWordRange:inString:language:

This delegate method returns an array of possible word completions from the spell checker, based on a partially completed string and a given range.

- (NSArray *)spellServer:(NSSpellServer *)sender suggestCompletionsForPartialWordRange:(NSRange)range inString:(NSString *)string language:(NSString *)language
Parameters
sender

The NSSpellServer object that sent this message.

range

The range of the partially completed word.

string

The string containing the partial word range.

language

The language to use for the completion.

Return Value

An array of NSString objects indicating possible completions.

Availability
  • Available in OS X v10.3 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSSpellServer.h

spellServer:suggestGuessesForWord:inLanguage:

Gives the delegate the opportunity to suggest guesses to the sender for the correct spelling of the given misspelled word in the specified language.

- (NSArray *)spellServer:(NSSpellServer *)sender suggestGuessesForWord:(NSString *)word inLanguage:(NSString *)language
Parameters
sender

The NSSpellServer object that sent this message.

word

The misspelled word.

language

The language to use for the guesses.

Return Value

An array of NSString objects indicating possible correct spellings.

Availability
  • Available in OS X v10.0 and later.
  • Available as part of an informal protocol prior to OS X v10.6.
Declared In
NSSpellServer.h