Skip to content

Instantly share code, notes, and snippets.

@averydev
Created March 12, 2013 01:16
Show Gist options
  • Save averydev/5139473 to your computer and use it in GitHub Desktop.
Save averydev/5139473 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment