Skip to content

Instantly share code, notes, and snippets.

@rblalock
Last active December 24, 2015 17:29
Show Gist options
  • Save rblalock/6835920 to your computer and use it in GitHub Desktop.
Save rblalock/6835920 to your computer and use it in GitHub Desktop.
static BOOL isLoaded;
/**
Singleton, shared instance
**/
+ (id)sharedInstance
{
__strong static id _sharedObject = nil;
if(isLoaded == NO) {
isLoaded = YES;
_sharedObject = [[self alloc] init];
}
return _sharedObject;
}
// Probably a better way.
/**
Singleton, shared instance
**/
+ (id)sharedInstance
{
static dispatch_once_t p = 0;
__strong static id _sharedObject = nil;
dispatch_once(&p, ^{
_sharedObject = [[self alloc] init];
});
return _sharedObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment