Word Count Problem
Word Count Problem
- Subject: Word Count Problem
- From: Matt Ball <email@hidden>
- Date: Mon, 3 May 2004 18:55:18 -0400
I am attempting to implement a simple word counter into my app. My code
looks like:
- (IBAction)countWords:(id)sender
{
int wordCount = 0, count = 0;
NSRange range;
NSString* textDocument = [textView string];
while(range.location != NSNotFound)
{
range = [[NSSpellChecker sharedSpellChecker]
checkSpellingOfString:textDocument startingAt:0 language:@"" wrap:YES
inSpellDocumentWithTag:0 wordCount:&count];
wordCount += count;
}
NSString* words = @" words.";
if(count == -1)
count = 0;
else if(count == 1)
words = @" word.";
[wordCountLabel setStringValue:[[@"Your document contains "
stringByAppendingString:[NSString stringWithFormat:@"%i", count]]
stringByAppendingString:words]];
[NSApp beginSheet: wordCountSheet
modalForWindow: mainWindow
modalDelegate: self
didEndSelector: nil
contextInfo: nil];
[NSApp endSheet:wordCountSheet];
}
It works fine for documents that have not set off a red flag in the
spellchecker. As soon as the document contains a word that the
spellchecker doesn't know, the word count stops working. The app
freezes when I try to do a word count. Can anyone offer any insights as
to why this is happening?
-- Matt Ball
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.