Skip to content

Instantly share code, notes, and snippets.

@ylem
Last active November 21, 2015 13:58
Show Gist options
  • Save ylem/4018420 to your computer and use it in GitHub Desktop.
Save ylem/4018420 to your computer and use it in GitHub Desktop.
Object-C create singleton class
+ (instancetype)sharedInstance
{
static MyClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[MyClass alloc] init];
});
return sharedInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment