Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Better singleton shared instance creation with use of GCD in Objective-C.
+ (instancetype)sharedInstance {
static TSClass *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
You can’t perform that action at this time.