Skip to content

Instantly share code, notes, and snippets.

@averydev
averydev / Objective-C Singleton
Created March 12, 2013 01:16
Handy method for maintaining an Objective-C Singleton
+ (MyClass *)sharedInstance
{
static MyClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[MyClass alloc] init];
// Do any other initialisation stuff here
});
return sharedInstance;