Re: Accessing shared (global) data object from nib
Re: Accessing shared (global) data object from nib
- Subject: Re: Accessing shared (global) data object from nib
- From: Clark Cox <email@hidden>
- Date: Tue, 16 Nov 2004 21:46:43 -0500
On Wed, 17 Nov 2004 13:15:30 +1100, Andrew White
<email@hidden> wrote:
> Joakim Danielson wrote:
> > Why don't you make CommonData a singleton, as such it can be called
> > from anywhere in your application, i.e [[CommonData sharedInstance]
> > someMethod].
>
> How do I instantiate a singleton? This is what I was getting at with the
> 'Add a method to the CommonData class to allow a single instance to be
> globally obtained' suggestion, but I don't know how to instantiate or store
> the singleton instance.
+(id)sharedInstance
{
static id instance;
if(instance == nil)
{
instance = [[CommonData alloc] init];
}
return instance;
}
--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden