Skip to content

Instantly share code, notes, and snippets.

@davidahouse
Created January 18, 2013 16:04
Show Gist options
  • Save davidahouse/4565614 to your computer and use it in GitHub Desktop.
Save davidahouse/4565614 to your computer and use it in GitHub Desktop.
singleton using dispatch_once
+ (<class> *)shared<whatever> {
static <class> *shared<class> = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared<class> = [[self alloc] init];
});
return shared<class>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment