• 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: Sharing a class' data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sharing a class' data


  • Subject: Re: Sharing a class' data
  • From: Charles Bennett <email@hidden>
  • Date: Fri, 07 Jun 2002 10:46:07 -0400

singleton pattern?

in class A

add a static variable and a method someting like this..



+ sharedInstance {
static ClassA *sharedInstance = nil;
if( !sharedInstance )
sharedInstance = [[ClassA alloc] init];
return sharedInstance;
}

now add the ususal accessor/setter methods for ClassA's data.

reference the data as

somevar = [[ClassA sharedInstance] somevar];

that way the first time classes B, C or D refrence ClassA, exactly ONE ClassA gets created
after that they all get the same instance of ClassA.


Is that what you wanted?

Chuck

Jesus De Meyer wrote:
>
> Hello,
>
> I wanna make a Cocoa class that is shared in several other classes. But
> I don't want to have different instances of the class, but rather would
> like to have its data shared. Basically it comes to having class A
> shared over other classes but letting class B, C and D reach the data of
> class A.
>
> Is this possible in Cocoa? Or would it be just easier to make a header
> file and make a struct?
>
> Thanks,
>
> Jesus
> ______________________________
> Jesus De Meyer
> CEO @ E dot software
> http://www.edot-software.com
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.

--
UPS Management software for OS X
http://www.powerguardian.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Sharing a class' data (From: Jesus De Meyer <email@hidden>)

  • Prev by Date: Re: Sharing a class' data
  • Next by Date: Keyboard Events
  • Previous by thread: Re: Sharing a class' data
  • Next by thread: Re: Sharing a class' data
  • Index(es):
    • Date
    • Thread