Skip to content

Instantly share code, notes, and snippets.

@theothertomelliott
Created September 28, 2015 20:57
Show Gist options
  • Save theothertomelliott/f10d398e26122386cecc to your computer and use it in GitHub Desktop.
Save theothertomelliott/f10d398e26122386cecc to your computer and use it in GitHub Desktop.
Thread-safe Objective-C singleton sharedInstance method.
+ (instancetype)sharedInstance {
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[[self class] alloc] init];
});
return sharedInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment