Skip to content

Instantly share code, notes, and snippets.

@wess
Created March 1, 2012 13:53
Show Gist options
  • Save wess/1949952 to your computer and use it in GitHub Desktop.
Save wess/1949952 to your computer and use it in GitHub Desktop.
Macro for Singleton with GCD
#define SINGLETON(classname) \
+(classname *)instance { \
static dispatch_once_t onetime; \
static classname *shared = nil; \
dispatch_once(&onetime, ^{ \
shared = [[classname alloc] init]; \
}); \
return shared; \
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment