Re: Subclassing NS(Mutable)Dictionary
Re: Subclassing NS(Mutable)Dictionary
- Subject: Re: Subclassing NS(Mutable)Dictionary
- From: Ondra Cada <email@hidden>
- Date: Wed, 24 Jul 2002 00:51:33 +0200
On Tuesday, July 23, 2002, at 11:18 , email@hidden wrote:
I would like to subclass NSDictionary, and then subsequently subclass
this subclass in order to create a mutable, ordered dictionary, so that
when I create or add entries to a dictionary (one of the subclasses), the
keys will be recorded in order (thus making an ordered dictionary). The
problem is that I don't know which methods are necessary to override, and
while it would seem easy enough, I have thoroughly confused myself. How
should I treat the class cluster in order to do this?
In short, by not subclassing, but embedding (as the Class Cluster document
says, or at least, had said when I've learnt it brand new in OpenStep ages
ago).
Make a new class with API you like, and make it contain the appropriate
objects -- something like
@interface OrderedDict {
NSMutableArray *array;
NSMutableDictionary *dictionary;
}
...
-(void)setObject:o forKey:k;
...
@end
@implementation OrderedDict
...
-(void)setObject:o forKey:k {
[dictionary setObject:o forKey:k];
[array addObject:k];
[array sortUsingSelector:@selector(caseInsensitiveCompare:)];
}
...
@end
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
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.