Defining a separate static variable for each type of subclass
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: Tue, 10 Jun 2003 10:28:20 +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.