• 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: Collection classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Collection classes


  • Subject: Re: Collection classes
  • From: "Timothy Reaves" <email@hidden>
  • Date: Thu, 8 Jan 2004 12:09:50 -0500 (EST)

> timothy,
>
>> I am implementing a table data source. I have a class (Foo) that has
>> an
>> instance attribute (bar) of type NSMutableSet that I want to have the
>> table display. The contract of bar is that it not allow duplicates,
>> so it
>> HAS to be a NSSet*, as that is the only collection that enforces that
>> contract. The Cocoa data sources in Cocoa want collections that are
>> indexable, and I understand why.
>
> use NSMutableArray and check for containsObject: before you insert.
>
> i rember apple having a private method called -(BOOL)addObjectIfAbsent:
> that was not in the headers of NSMutableArray. so before you add such a
> method as a category, try to just create a header for it. if you can
> use it fine (it's still in there somewhere) if you get
> selectorNotRecognized just implement it yourself and you can use
> NSMutableArray as an indexable list with unique entries.
>
>
Well, that would work, and it might be the way I end up going. But I
do not like it. It the code I was working on were meant to be
reused, even by me, it could be very easy to confuse why I was using
an array instead of a set, when it is clear that a set is called for.

If I wanted to add a class, an NSOrderedSet would be very easy to
create composing an array into it, and wrapping all the mutators with
the check you suggest.
_______________________________________________
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.

References: 
 >Collection classes (From: T Reaves <email@hidden>)
 >Re: Collection classes (From: Todd Blanchard <email@hidden>)
 >Re: Collection classes (From: Alexander Spohr <email@hidden>)

  • Prev by Date: NSWindow's firstResponder and a pointer to that object.
  • Next by Date: Re: class variables and class methods
  • Previous by thread: Re: Collection classes
  • Next by thread: Re: Collection classes
  • Index(es):
    • Date
    • Thread