Mac Developer Library

Developer

Foundation Framework Reference NSSpellServerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSSpellServerDelegate

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

Inheritance


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.6 and later.
  • Gives the delegate the opportunity to analyze both the spelling and grammar simultaneously, which is more efficient.

    Declaration

    Swift

    optional func spellServer(_ sender: NSSpellServer, checkString stringToCheck: String, offset offset: Int, types checkingTypes: NSTextCheckingTypes, options options: [NSObject : AnyObject]?, orthography orthography: NSOrthography?, wordCount wordCount: UnsafeMutablePointer<Int>) -> [AnyObject]?

    Objective-C

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    optional func spellServer(_ sender: NSSpellServer, suggestGuessesForWord word: String, inLanguage language: String) -> [AnyObject]?

    Objective-C

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func spellServer(_ sender: NSSpellServer, checkGrammarInString string: String, language language: String?, details outDetails: AutoreleasingUnsafeMutablePointer<NSArray?>) -> NSRange

    Objective-C

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.5 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func spellServer(_ sender: NSSpellServer, findMisspelledWordInString stringToCheck: String, language language: String, wordCount wordCount: UnsafeMutablePointer<Int>, countOnly countOnly: Bool) -> NSRange

    Objective-C

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func spellServer(_ sender: NSSpellServer, didForgetWord word: String, inLanguage language: String)

    Objective-C

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func spellServer(_ sender: NSSpellServer, didLearnWord word: String, inLanguage language: String)

    Objective-C

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func spellServer(_ sender: NSSpellServer, suggestCompletionsForPartialWordRange range: NSRange, inString string: String, language language: String) -> [AnyObject]?

    Objective-C

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.3 and later.

    Available as part of an informal protocol prior to OS X v10.6.

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

    Declaration

    Swift

    optional func spellServer(_ sender: NSSpellServer, recordResponse response: Int, toCorrection correction: String, forWord word: String, language language: String)

    Objective-C

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.