• 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: Subclassing NS(Mutable)Dictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Subclassing NS(Mutable)Dictionary
      • From: email@hidden
References: 
 >Subclassing NS(Mutable)Dictionary (From: email@hidden)

  • Prev by Date: NSFileWrapper in Java
  • Next by Date: RE: Bolding a range in a mutable string
  • Previous by thread: Subclassing NS(Mutable)Dictionary
  • Next by thread: Re: Subclassing NS(Mutable)Dictionary
  • Index(es):
    • Date
    • Thread