Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSSpellChecker

Inherits from
Package
com.apple.cocoa.application
Companion guide

Overview

The NSSpellChecker class gives any application an interface to the Cocoa spell-checking service. To handle all its spell checking, an application needs only one instance of NSSpellChecker. It provides a 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 in Mac OS X version 10.3.

Tasks

Constructors

Getting the Spell Checker

Managing the Spelling Panel

Checking Spelling

Setting the Language

Managing the Spelling Process

Constructors

NSSpellChecker

Creates an empty NSSpellChecker.

public NSSpellChecker()

Static Methods

sharedSpellChecker

Returns the NSSpellChecker (one per application).

public static NSSpellChecker sharedSpellChecker()

See Also

sharedSpellCheckerExists

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

public static boolean sharedSpellCheckerExists()

See Also

uniqueSpellDocumentTag

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

public static int uniqueSpellDocumentTag()

Discussion

Use this method to generate tags to avoid collisions with other objects that can be spell checked.

Instance Methods

accessoryView

Returns the Spelling panel’s accessory NSView object.

public NSView accessoryView()

See Also

checkSpellingOfString

Starts the search for a misspelled word in stringToCheck starting at startingOffset within the string object.

public NSRange checkSpellingOfString(String stringToCheck, int startingOffset)

Discussion

Returns the range of the first misspelled word. Wrapping occurs, but no ignored-words dictionary is used.

closeSpellDocumentWithTag

Notifies the receiver that the user has finished with the ignored-word document identified by tag, causing it to throw that dictionary away.

public void closeSpellDocumentWithTag(int tag)

completionsForPartialWordRange

public NSArray completionsForPartialWordRange(NSRange range, String string, String language, int tag)

Discussion

Returns an array of strings from the spell checker dictionary representing complete words that the user might be trying to type, based off a partial word at the given range. Strings are returned in the order they should be presented. The language argument specifies the language used in the string. If language is null, the current selection in the Spelling panel’s pop-up menu is used.

Availability

countWordsInString

Returns the number of words in stringToCount.

public int countWordsInString(String stringToCount, String language)

Discussion

The language argument specifies the language used in the string. If language is null, the current selection in the Spelling panel’s pop-up menu is used.

guessesForWord

Returns an array of suggested spellings for the misspelled word word.

public NSArray guessesForWord(String word)

Discussion

If word contains all capital letters, or its first letter is capitalized, the suggested words are capitalized in the same way.

ignoredWords

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

public NSArray ignoredWords(int tag)

Discussion

Invoke this method before closeSpellDocumentWithTag if you want to store the ignored words.

See Also

ignoreWord

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

public void ignoreWord(String wordToIgnore, int tag)

Discussion

You should invoke this method from within your implementation of the NSIgnoreMisspelledWords interface’s ignoreSpelling method.

language

Returns the current language used in spell checking.

public String language()

See Also

setAccessoryView

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

public void setAccessoryView(NSView aView)

Discussion

This method posts a WindowDidResizeNotification with the Spelling panel object to the default notification center.

See Also

setIgnoredWords

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

public void setIgnoredWords(NSArray someWords, int tag)

See Also

setLanguage

Sets the language to use in spell checking to language.

public boolean setLanguage(String language)

Discussion

Returns whether the Language pop-up list in the Spelling panel lists language.

See Also

setWordFieldStringValue

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

public void setWordFieldStringValue(String aString)

spellingPanel

Returns the spell checker’s panel.

public NSPanel spellingPanel()

updateSpellingPanelWithMisspelledWord

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

public void updateSpellingPanelWithMisspelledWord(String word)

Discussion

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



Next Page > Hide TOC


© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.