Skip to content

Instantly share code, notes, and snippets.

@ArchieGoodwin
Created March 18, 2014 08:37
Show Gist options
  • Save ArchieGoodwin/9615906 to your computer and use it in GitHub Desktop.
Save ArchieGoodwin/9615906 to your computer and use it in GitHub Desktop.
Singleton declaration
@interface
+(id)sharedInstance;
@implementation
- (id)init {
self = [super init];
#if !(TARGET_IPHONE_SIMULATOR)
#else
#endif
if(self)
{
//init some stuff
}
return self;
}
+(id)sharedInstance
{
static dispatch_once_t pred;
static YourObject *sharedInstance = nil;
dispatch_once(&pred, ^{
sharedInstance = [[YourObject alloc] init];
});
return sharedInstance;
}
- (void)dealloc
{
abort();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment