• 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
Re: Shared Instance of a class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shared Instance of a class


  • Subject: Re: Shared Instance of a class
  • From: Mike Abdullah <email@hidden>
  • Date: Fri, 19 May 2006 20:46:06 +0100

Cheers guys. I hadn't realised that you could use static outside of a method. This way I can set the value in my object's init method :)

Mike.

On 19 May 2006, at 19:41PM, Tommy Nordgren wrote:


On 19 maj 2006, at 19.42, Mike Abdullah wrote:

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?

Mike.
_______________________________________________
In your implementation file have a static pointer to your class. Assign self to it in your awakeFromNib method.
Now you can have a class method that returns the shared instance, or throws an exception if it's not defined.
------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone"
email@hidden




_______________________________________________ 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
  • Follow-Ups:
    • RE: Shared Instance of a class
      • From: "Christopher Hickman" <email@hidden>
References: 
 >Shared Instance of a class (From: Mike Abdullah <email@hidden>)
 >Re: Shared Instance of a class (From: Tommy Nordgren <email@hidden>)

  • Prev by Date: Re: How to implement multicast?
  • Next by Date: RE: Shared Instance of a class
  • Previous by thread: Re: Shared Instance of a class
  • Next by thread: RE: Shared Instance of a class
  • Index(es):
    • Date
    • Thread