• 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
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: class keeps track of object


  • Subject: Re: class keeps track of object
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Wed, 2 Jul 2008 00:43:51 +0200

search for singleton pattern (in the archives and in Apple doc too).

The simplest way to do it is (not thread safe):

@implementation Foo

+ (Bar *)sharedFoo {
static Foo *shardInstance = nil;
if (!sharedInstance)
	sharedInstance = [[Foo alloc] init];
return sharedInstance;
}

@end


Le 2 juil. 08 à 00:35, Daniel Richman a écrit :

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)

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


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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>)

  • Prev by Date: class keeps track of object
  • Next by Date: Re: class keeps track of object
  • Previous by thread: class keeps track of object
  • Next by thread: Re: class keeps track of object
  • Index(es):
    • Date
    • Thread