• 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
RE: counting characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: counting characters


  • Subject: RE: counting characters
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Thu, 15 Apr 2004 16:24:51 -0400

> On 15. Apr 2004, at 20:09, Jonathan E. Jackel wrote:
>
> > Of course, you can put your code in a category on NSString call it the
> > Cocoa
> > way:
> >
> > int occurrences = [theString numberOfOccurrences:searchString];
>
> Unfortunately if we need to count the characters in an
> NSAttributedString instead (or perhaps count objects in an NSArray)
> then we cannot re-use your implementation, which we can with
> std::count.


Is there something wrong with [[theAttributedString string]
numberOfOccurrences:searchString]?

If your point is that you can't hand an arbitrary object to the method and
count stuff, yes, that's true. So what? We have a -count method for arrays
and a -length method for strings and people don't complain about that.
Doesn't seem like that big a deal to me, at least in this instance.

If it's important to deal with multiple kinds of objects (which the original
poster did not mention as a requirement), you can create a generic method
that tests self for -isKindOfClass: or -respondsToSelector: and put it in a
category on NSObject. You don't HAVE to resort to CocoaSTL to be able to
reuse your code, although I can see why that might be useful.

Jonathan
_______________________________________________
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: counting characters
      • From: Allan Odgaard <email@hidden>
References: 
 >Re: counting characters (From: Allan Odgaard <email@hidden>)

  • Prev by Date: Re: C++ templates?
  • Next by Date: Re: HotKey contains click
  • Previous by thread: Re: counting characters
  • Next by thread: Re: counting characters
  • Index(es):
    • Date
    • Thread