Skip to content

Instantly share code, notes, and snippets.

@ehuynh
Created April 16, 2012 05:48
Show Gist options
  • Save ehuynh/2396566 to your computer and use it in GitHub Desktop.
Save ehuynh/2396566 to your computer and use it in GitHub Desktop.
iOS Singleton
static MyObject *singleton = nil;
+(MyObject *) sharedInstance {
NSLog (@"sharedInstance called.");
if (nil != singleton) return singleton;
static dispatch_once_t predicate;
dispatch_once(&predicate, ^{
singleton = [[MyObject alloc] init];
});
return singleton;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment