Last active
December 24, 2015 17:19
-
-
Save monkeydom/6834911 to your computer and use it in GitHub Desktop.
New try on Singleton non-redundancy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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