Inherits From:
NSObject
Conforms To:
NSObject (NSObject)
Declared In:
AppKit/NSSpellServer.h
To make use of NSSpellServer, you write a small program that creates an NSSpellServer instance and a delegate that responds to messages asking it to find a misspelled word and to suggest guesses for a misspelled word. Send the NSSpellServer registerLanguage:byVendor:
messages to tell it the languages your delegate can handle.
The program that runs your spelling checker should not be built as an Application Kit application, but as a simple program. Suppose you supply spelling checkers under the vendor name "Acme." Suppose the file containing the code for your delegate is called AcmeEnglishSpellChecker. Then the following might be your program's main
:
void main()
{
NSSpellServer *aServer = [[NSSpellServer alloc] init];
if ([aServer registerLanguage:"English" byVendor:"Acme"]) {
[aServer setDelegate:[[AcmeEnglishSpellChecker alloc] init]];
[aServer run];
fprintf(stderr, "Unexpected death of Acme SpellChecker!\n");
else {
fprintf(stderr, "Unable to check in Acme SpellChecker.\n");
}
}
Your delegate is an instance of a custom subclass. (It's simplest to make it a subclass of NSObject, but that's not a requirement.) Given an NSString, your delegate must be able to find a misspelled word by implementing the method spellServer:findMisspelledWordInString:language:wordCount:countOnly:
. Usually, this method also reports the number of words it has scanned, but that isn't mandatory.
Optionally, the delegate may also suggest corrections for misspelled words. It does so by implementing the method spellServer:suggestGuessesForWord:inLanguage:
.
A service descriptor is an entry in a text file called services
. Usually it's located within the bundle that also contains your spelling checker's executable file. The bundle (or directory) that contains the services file must have a name ending in ".service" or ".app". The system looks for service bundles in a standard set of directories.
A spell checker service availability notice has a standard format, illustrated in the following example for the Acme spelling checker:
Spell Checker: Acme
Language: French
Language: English
Executable: franglais.daemon
The first line identifies the type of service; for a spelling checker, it must say "Spell Checker:" followed by your vendor name. The next line contains the English name of a language your spelling checker is prepared to check. (The language must be one your system recognizes.) If your program can check more than one language, use an additional line for each additional language. The last line of a descriptor gives the name of the service's executable file. (It requires a complete path if it's in a different directory.)
If there's a service descriptor for your Acme spelling checker and also a service descriptor for the English checker provided by a vendor named Consolidated, a user looking at the Spelling panel's pop-up list would see:
English (Acme)
English (Consolidated)
French (Acme)
isWordInUserDictionaries:caseSensitive:
will report YES rather than NO).
delegate
Returns the NSSpellServer's delegate.
See also:
- setDelegate:
isWordInUserDictionaries:
(NSString *)word caseSensitive:
(BOOL)flag
Indicates whether word is in the user's list of learned words or the document's list of words to ignore. If YES, the word is acceptable to the user. flag indicates whether the comparison is to be case-sensitive.
registerLanguage:
(NSString *)language byVendor:
(NSString *)vendor
Notifies the NSSpellServer of a language your spelling checker can check. language is the English name of a language on NeXT's list of languages. vendor identifies the vendor (to distinguish your spelling checker from those that others may offer for the same language). If your spelling checker supports more than one language, it should invoke this method once for each language. Registering a language/vendor combination causes it to appear in the Spelling Panel's pop-up list of spelling checkers.
Returns YES if the language is registered, NO if for some reason it can't be registered.
run
Causes the NSSpellServer to start listening for spell-checking requests. This method starts a loop that never returns; you need to set the NSSpellServer's delegate before sending this message.
See also:
- setDelegate:
setDelegate:
(id)anObject
Assigns a delegate to the NSSpellServer. Since the delegate is where the real work is done, this is an essential step before telling the NSSpellServer to run.
See also:
- delegate
, - run
Methods Implemented by the Delegate
spellServer:
(NSSpellServer *)senderdidForgetWord:
(NSString *)wordinLanguage:
(NSString *)language
Notifies the delegate that word has been removed from the user's list of acceptable words. If your delegate maintains a similar auxiliary word list, you may wish to edit the list accordingly.
spellServer:
(NSSpellServer *)senderdidLearnWord:
(NSString *)wordinLanguage:
(NSString *)language
Notifies the delegate that word has been added to the user's list of acceptable words. If your delegate maintains a similar auxiliary word list, you may wish to edit the list accordingly.
spellServer:
(NSSpellServer *)senderfindMisspelledWordInString:
(NSString *)stringToChecklanguage:
(NSString *)languagewordCount:
(int *)wordCountcountOnly:
(BOOL)countOnly
Asks the delegate to search for a misspelled word in stringToCheck, using language, and marking the first misspelled word found by returning its range within the string object. In wordCount, return by reference the number of words from the beginning of the string object until the misspelled word (or the end-of-string). If countOnly is YES, just count the words in the string object; do not spell-check. Send isWordInUserDictionaries:caseSensitive:
to the spelling server to determine if word exists in the user's language dictionaries.
spellServer:
(NSSpellServer *)sendersuggestGuessesForWord:
(NSString *)wordinLanguage:
(NSString *)language
Gives the delegate the opportunity to suggest guesses for the correct spelling of the misspelled word. Return the guesses as an array of NSStrings.