• 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
Defining a separate static variable for each type of subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Defining a separate static variable for each type of subclass


  • Subject: Defining a separate static variable for each type of subclass
  • From: Wade Tregaskis <email@hidden>
  • Date: Mon, 9 Jun 2003 17:35:13 +1000

The topic says it all, if you can understand it. I have a generic superclass - an extension of NSObject - in which I have a static object, an NSMutableArray. From a design point of view, there can be a separate copy of this object for each type of subclass. Conversely, though, there doesn't have to be - all items can be stored in the one array, and I can tell them apart from their class. But this would become very inefficient if you had one subclass with a thousand entries, and a hundred other subclasses with only a few - why should every subclass suffer because of one?

So anyway, I'd like to keep a separate NSMutableArray for each unique subclass. I can certainly do this myself with an NSDictionary (using [self class] as the key, and my NSMutableArray as the data), but I'm just wondering if there's some standard way of doing this, that will save me the extra coding and allow my class to work faster (by not having to do a dictionary lookup each time to get the appropriate array).

If it helps, the existing code can be found in the Keychain framework, available at <http://sourceforge.net/projects/keychain/> or on request via email. The class in question is called NSCachedObject*.

Wade Tregaskis
-- Sed quis custodiet ipsos custodes?

* = Yes, I'm aware the use of the NS prefix is questionable. That's a debate for another time. :)
_______________________________________________
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.
  • Prev by Date: message dialog...
  • Next by Date: Re: C question for you old guys ;-)
  • Previous by thread: Defining a separate static variable for each type of subclass
  • Next by thread: Re: openURL Question
  • Index(es):
    • Date
    • Thread