Re: Collection classes
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.