Skip to content

Instantly share code, notes, and snippets.

@rismay
Created November 24, 2013 03:11
Show Gist options
  • Save rismay/7622846 to your computer and use it in GitHub Desktop.
Save rismay/7622846 to your computer and use it in GitHub Desktop.
Easy singleton. Add this to your PCH and every class will be singletonable. Exercise caution.
#define WSM_SINGLETON_WITH_NAME(sharedInstanceName) \
+ (instancetype) sharedInstanceName { \
static id sInstance; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
sInstance = [[self alloc] init]; \
}); \
return sInstance; \
} \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment