Skip to content

Instantly share code, notes, and snippets.

@tomassliz
Last active December 24, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomassliz/6752841 to your computer and use it in GitHub Desktop.
Save tomassliz/6752841 to your computer and use it in GitHub Desktop.
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