Re: Class Constants
Re: Class Constants
- Subject: Re: Class Constants
- From: Gregory Weston <email@hidden>
- Date: Sun, 30 May 2004 21:31:53 -0400
On May 30, 2004, at 8:34 PM, James Stroud wrote:
I would like to make a NSDictionary filled with the same values
available to all instances of a class. (It would not change from
instance to instance, but all instances will need it. I want to read
this dictionary in from a plist, but I think it would be wasteful for
each instance to have its own copy of the dictionary. Its not obvious
to me how I would go about implementing this. Does anyone have any
advice.
It's generally called a singleton. You have a factory (class) method
that will return your dictionary, loading/creating it if necessary, but
holding a reference to it once it has been brought into being.
+ (NSDictionary*)mySharedDictionary
{
static NSDictionary* sDict = NULL;
if(sDict == NULL)
{
/* load/create as necessary */
/* make sure you retain it if appropriate */
}
return sDict;
}
_______________________________________________
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.