Skip to content

Instantly share code, notes, and snippets.

@dmhts
Created November 11, 2016 09:34
Show Gist options
  • Save dmhts/29afa444f01bde3a6889e65e3463fe7e to your computer and use it in GitHub Desktop.
Save dmhts/29afa444f01bde3a6889e65e3463fe7e to your computer and use it in GitHub Desktop.
Obj-C thread-safe singleton
+ (instancetype)sharedInstance {
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment