Skip to content

Instantly share code, notes, and snippets.

@pfitz
Forked from monkeydom/SingletonMacro.h
Created October 10, 2013 06:39
Show Gist options
  • Save pfitz/6914026 to your computer and use it in GitHub Desktop.
Save pfitz/6914026 to your computer and use it in GitHub Desktop.
/** usage example
@implementation ABCPlayerManager
+ (instancetype)sharedPlayerManager {
return TCM_SINGLETON(ABCPlayerManager);
}
@end
*/
#define TCM_SINGLETON(THECLASS) ({ \
static THECLASS *s_sharedInstance = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
s_sharedInstance = [THECLASS new]; \
}); \
s_sharedInstance;\
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment