Skip to content

Instantly share code, notes, and snippets.

@manmal
Created March 11, 2012 13:55
Show Gist options
  • Save manmal/2016521 to your computer and use it in GitHub Desktop.
Save manmal/2016521 to your computer and use it in GitHub Desktop.
Synthesize Singleton
#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