Created
March 11, 2012 13:55
-
-
Save manmal/2016521 to your computer and use it in GitHub Desktop.
Synthesize Singleton
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
#define SYNTHESIZE_SINGLETON_FOR_CLASS_WITH_CUSTOM_METHOD_NAME(classname, methodname) \ | |
\ | |
static classname *shared##classname = nil; \ | |
\ | |
+ (classname *)methodname \ | |
{ \ | |
@synchronized(self) \ | |
{ \ | |
if (shared##classname == nil) \ | |
{ \ | |
shared##classname = [[self alloc] init]; \ | |
} \ | |
} \ | |
\ | |
return shared##classname; \ | |
} | |
#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \ | |
\ | |
SYNTHESIZE_SINGLETON_FOR_CLASS_WITH_CUSTOM_METHOD_NAME(classname, shared##classname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment