Skip to content

Instantly share code, notes, and snippets.

@dmur
Last active August 20, 2018 13:45
Show Gist options
  • Save dmur/5689050 to your computer and use it in GitHub Desktop.
Save dmur/5689050 to your computer and use it in GitHub Desktop.
Best practice for Singleton class method in modern Objective-C
+ (id)sharedInstance
{
static <#ClassName#> *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