Re: Collection classes
Re: Collection classes
- Subject: Re: Collection classes
- From: j o a r <email@hidden>
- Date: Thu, 8 Jan 2004 16:22:35 +0100
On 2004-01-08, at 15.08, Timothy Reaves wrote:
>
What's not to like? Are you kidding? :-)
No, we're not kidding - and the arguments you've raised so far doesn't
really convince me that there is a problem.
>
New classes might not be needed, but some new functionality is.
>
Whereas
>
I'm still learning Objective-C, I'm not sure what I want can be done
>
with
>
an interface, although if it could, that'd be fine.
..as you're still learning Cocoa and Objective-C, and especially as
you're comparing with Java, it's not surprising that you think that the
class library is lacking, simply because it's small. IMO that is a
great advantage of Cocoa.
>
But how should I then model my non-indexable collection in an indexable
>
way? So far I have not found an easy way to do this in Cocoa.
>
Converting
>
the collection to an NSArray doesn't work, because the then as
>
additions
>
and deletions are made I must update two objects! Not good. What is
>
needed is an NSOrderedSet; whether that is accomplised as a class, or
>
simply adding a catagory doesn't really matter.
If you *really* need to have this as a feature of the collection - and
not part of the accessor methods in the controller - simply do this:
@interface NSMutableArray (MyArrayAdditions)
- (void) addObjectIfMissing:(id) obj;
@end
@implementation NSMutableArray (MyArrayAdditions)
- (void) addObjectIfMissing:(id) obj
{
if ((obj != nil) && ![self containsObject: obj])
{
[self addObject: obj];
}
}
@end
And voila, an ordered collection of unique items. No need for a
separate class for that purpose.
j o a r
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.