Singleton Class sample

//.h file should contain

+ (MySingleton *)sharedInstance;

 

//.m file must declare as below

+ (MySingleton *)sharedInstance

{

static dispatch_once_t once;

static MySingleton *instance;

dispatch_once(&once, ^{

instance = [[MySingleton alloc] init];

});

return instance;

}

– (id)init

{

if (self = [super init])

{

     someProperty =@”test”;

}

return self;

}


Discover more from CODE t!ps

Subscribe to get the latest posts sent to your email.

Scroll to Top

Discover more from CODE t!ps

Subscribe now to keep reading and get access to the full archive.

Continue reading