Re: Shared Instance of a class
Re: Shared Instance of a class
- Subject: Re: Shared Instance of a class
- From: Keary Suska <email@hidden>
- Date: Fri, 19 May 2006 12:34:08 -0600
on 5/19/06 11:42 AM, email@hidden purportedly said:
> I have a custom class that I instanciate in my MainMenu nib. What I
> want to do is be able to issue the command:
>
> [MyClass sharedInstance]
>
> and get that particular instance of the class. I know how to do this
> with a class that is only instanciated once the sharedInstance
> message is received, but the object pre-exists.
>
> NSDocumentController is capable of this. Any ideas?
I am assuming that you want to access the instance from objects that
*aren't* instantiated in the nib (or are in a different nib), since all you
would do otherwise is set an outlet.
If you have access to an object that has access to the desired object, you
could simply have an accessor-type method in that object for returning the
instance.
In any case, AFAIK, there has to be some connection chain, whether by
outlets, actions, or ownership. It doesn't have to be direct, but there must
be a traceable relationship. The main bit is that the object you want is
instantiated in the nib, while NSDocumentController is not usually
instantiated this way, and as I understand the "shared instance" doesn't
actually exist until the class method is called at some point--i.e. that if
the instance doesn't yet exist it is created at that moment.
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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