• 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: class keeps track of object [solved]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: class keeps track of object [solved]


  • Subject: Re: class keeps track of object [solved]
  • From: Daniel Richman <email@hidden>
  • Date: Tue, 01 Jul 2008 15:51:03 -0700

Thanks! Exactly what I was looking for.

Daniel


Jonathan Hess wrote:
Han Daniel -

You can use a global variable just like you would in C:

    static Foo *bar = nil;

    @implementation Foo
    + (id)bar {
        if (!bar) {
            bar = [[Foo alloc] init];
        }
        return bar;
    }
    @end


Thats the simple single threaded case. Things get much more interesting if you want to be able to call 'bar' from multiple threads.


Compiled in Mail -
Jon Hess

On Jul 1, 2008, at 3:35 PM, Daniel Richman wrote:

Hi All,

I have created a class (call it Foo) that there will be one and only one instance of (call it Bar). I need some way to have Foo keep a pointer to Bar, so when another object asks for the pointer to Bar, Foo will be able to return the pointer.

Presumably this can be done, as NSNotificationCenter has the defaultCenter method. But I don't know how to go about it. Any ideas?

Daniel
_______________________________________________

Cocoa-dev mailing list (email@hidden <mailto:email@hidden>)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >class keeps track of object (From: Daniel Richman <email@hidden>)
 >Re: class keeps track of object (From: Jonathan Hess <email@hidden>)

  • Prev by Date: Re: class keeps track of object
  • Next by Date: Re: Getting mouse moved events on overlay windows
  • Previous by thread: Re: class keeps track of object
  • Next by thread: Re: class keeps track of object
  • Index(es):
    • Date
    • Thread