-
-
Save dominik-hadl/5517734 to your computer and use it in GitHub Desktop.
GCDSingleton Macro + @ArvinB changes.
This file contains 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
/*! | |
* @function Singleton GCD Macro | |
*/ | |
#ifndef SINGLETON_GCD | |
#define SINGLETON_GCD(classname) \ | |
\ | |
+ (classname *)shared##classname { \ | |
\ | |
static dispatch_once_t pred; \ | |
__strong static classname * shared##classname = nil;\ | |
dispatch_once( &pred, ^{ \ | |
shared##classname = [[self alloc] init]; }); \ | |
return shared##classname; \ | |
} | |
#endif |
This file contains 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
@interface MyClass : NSObject | |
+ (MyClass *) sharedMyClass; | |
@end |
This file contains 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
#import "MyClass.h" | |
@implementation MyClass | |
SINGLETON_GCD(MyClass); | |
- (id) init { | |
if ( (self = [super init]) ) { | |
// Initialization code here. | |
} | |
return self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment