• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Word Count Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Word Count Problem
      • From: cricket <email@hidden>
    • Re: Word Count Problem
      • From: cricket <email@hidden>
  • Prev by Date: Re: Obj-C in a dylib
  • Next by Date: Re: OT? Why are list archive search results so lame?
  • Previous by thread: Re: NSView and backgrounds, selectable
  • Next by thread: Re: Word Count Problem
  • Index(es):
    • Date
    • Thread