Skip to content

Instantly share code, notes, and snippets.

@Huang-Libo
Last active September 7, 2017 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Huang-Libo/4d4e6080ec467faf05ebe1b02b34704c to your computer and use it in GitHub Desktop.
Save Huang-Libo/4d4e6080ec467faf05ebe1b02b34704c to your computer and use it in GitHub Desktop.
Objective-C singleton
// `dispatch_once' singleton initialisation
+ (id)sharedInstance {
static EOCClass *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