Skip to content

Instantly share code, notes, and snippets.

@yoman07
Created February 15, 2014 16:51
Show Gist options
  • Save yoman07/9021877 to your computer and use it in GitHub Desktop.
Save yoman07/9021877 to your computer and use it in GitHub Desktop.
Singleton in objective-c
- (id) sharedInstance {
static MyObject *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[MyObject alloc] init];
});
return sharedInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment