iOS Singleton

Some of the simple things such as passing variables has turned to be complicated in objective languages. Here useful method to do it by create a singleton classes just to handle the static variable.

@interface VariableStore : NSObject
{     // Place any "global" variables here
// message from which our instance is obtained
+ (VariableStore *)sharedInstance;

@implementation VariableStore
+ (VariableStore *)sharedInstance
// the instance of this class is stored here    
static VariableStore *myInstance = nil;
// check to see if an instance already exists    
if (nil == myInstance)
myInstance  = [[[self class] alloc] init];
// initialize variables here     }    
// return the instance of this class    
return myInstance; } @end


Reference Links: