Skip to content

Instantly share code, notes, and snippets.

@bragisig
Created August 22, 2013 12:21
Show Gist options
  • Save bragisig/6306483 to your computer and use it in GitHub Desktop.
Save bragisig/6306483 to your computer and use it in GitHub Desktop.
Objective-C Singleton, creating shared instance
+ (MyClass *)sharedInstance
{
// Static local predicate must be initialized to 0
static MyClass *sharedInstance = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
sharedInstance = [[MyClass alloc] init];
// Do any other initialisation stuff here
});
return sharedInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment