Re: Sharing a class' data
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.