Class

NSSpellChecker

An interface to the Cocoa spell-checking service.

Overview

To handle all its spell checking, an app needs only one instance of NSSpellChecker, known as the spell checker. Using the spell checker you manage the Spelling panel, in which the user can specify decisions about words that are suspect. The spell checker also offers the ability to provide word completions to augment the text completion system.

Topics

Getting the Spell Checker

class var shared: NSSpellChecker

Returns the NSSpellChecker (one per application).

class var sharedSpellCheckerExists: Bool

Returns whether the application’s NSSpellChecker has already been created.

Configuring Spell Checkers Languages

var availableLanguages: [String]

Provides a list of all available languages.

var userPreferredLanguages: [String]

Provides a subset of the available languages to be used for spell checking.

var automaticallyIdentifiesLanguages: Bool

Sets whether the spell checker will automatically identify languages.

func language()

Returns the current language used in spell checking.

func setLanguage(String)

Returns whether the specified language is in the Spelling pop-up list.

Managing Panels

var spellingPanel: NSPanel

Returns the spell checker’s panel.

var substitutionsPanel: NSPanel

Returns the substitutions panel.

func updateSpellingPanel(withGrammarString: String, detail: [String : Any])

Specifies a grammar-analysis detail to highlight in the Spelling panel.

func updatePanels()

Updates the available panels to account for user changes.

var accessoryView: NSView?

Makes an view an accessory of the Spelling panel by making it a subview of the panel’s content view.

var substitutionsPanelAccessoryViewController: NSViewController?

Sets the substitutions panel’s accessory view.

Checking Strings for Spelling and Grammar

Managing the Spell-Checking Process

class func uniqueSpellDocumentTag()

Returns a guaranteed unique tag to use as the spell-document tag for a document.

func closeSpellDocument(withTag: Int)

Notifies the receiver that the user has finished with the tagged document.

func ignoreWord(String, inSpellDocumentWithTag: Int)

Instructs the spell checker to ignore all future occurrences of wordToIgnore in the document identified by tag.

func ignoredWords(inSpellDocumentWithTag: Int)

Returns the array of ignored words for a document identified by tag.

func setIgnoredWords([String], inSpellDocumentWithTag: Int)

Initializes the ignored-words document (a dictionary identified by tag with someWords), an array of words to ignore.

func setWordFieldStringValue(String)

Sets the string that appears in the misspelled word field, using the string object aString.

func updateSpellingPanel(withMisspelledWord: String)

Causes the spell checker to update the Spelling panel’s misspelled-word field to reflect word.

func completions(forPartialWordRange: NSRange, in: String, language: String?, inSpellDocumentWithTag: Int)

Provides a list of complete words that the user might be trying to type based on a partial word in a given string.

func hasLearnedWord(String)

Indicates whether the spell checker has learned a given word.

func unlearnWord(String)

Tells the spell checker to unlearn a given word.

func learnWord(String)

Adds the word to the spell checker dictionary.

func userQuotesArray(forLanguage: String)

Returns the default values for quote replacement.

var userReplacementsDictionary: [String : String]

Returns the dictionary used when replacing words.

Data Detector Interaction

func menu(for: NSTextCheckingResult, string: String, options: [NSSpellChecker.OptionKey : Any]? = nil, atLocation: NSPoint, in: NSView)

Provides a menu containing contextual menu items suitable for certain kinds of detected results.

Notifications

class let didChangeAutomaticSpellingCorrectionNotification: NSNotification.Name

This notification is posted when the spell checker did change text using automatic spell checking correction. The are posted to the application’s default notification center.

class let didChangeAutomaticTextReplacementNotification: NSNotification.Name

Posted when the spell checker changed text using automatic text replacement. This notification is posted to the app’s default notification center.

Relationships

Inherits From

Conforms To

See Also

Spell Checking

protocol NSChangeSpelling

A protocol that responder objects can implement to correct a misspelled word.

protocol NSIgnoreMisspelledWords

A method that enables the Ignore button in the Spelling panel to function properly.