Singleton class in Objective c

The use of singleton class is used to reuse the stuff which is declared in the single ton class.with the help of a singleton class the object for a class created only one and can be used through out the project.

Here is the syntax for singleton class..

the string can be accessed by

labl.text=[[SingleTonClass singleTonMethodObj]singletonClassString];

static SingleTonClass *singleTonMethodObj=nil;
if (!singleTonMethodObj) {
singleTonMethodObj=[[super allocWithZone:nil]init];
return singleTonMethodObj;

+(id)allocWithZone:(NSZone *)zone

return [self singleTonMethodObj];

self= [super init];
singletonClassString=@”Hii am from singleTon Class”;

return self;





The string declared here is the singletonClassString   can be used in all other classes by using the following syntax

[[SingleTonClass singleTonMethodObj]singletonClassString];



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s