Created
May 26, 2013 08:41
-
-
Save ziggear/5652106 to your computer and use it in GitHub Desktop.
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
// Created by ziggear on 13-5-26 | |
// fw & courtesy: http://cocoasamurai.blogspot.com/2011/04/singletons-your-doing-them-wrong.html | |
// usage: | |
// @implementation SomeClass | |
// .... | |
// kSingletonSynthesize(SomeClass) | |
// @end | |
//Thread-safe block | |
#define kRunInSecurutyBlock(lines) static dispatch_once_t pred; dispatch_once(&pred, ^{ \ | |
lines \ | |
}); | |
//Singleton | |
#define kSingletonSynthesize(Class) + (id)sharedMan { \ | |
static id sharedManager = nil;\ | |
if (self == [Class class]) { \ | |
kRunInSecurutyBlock(sharedManager = [[Class alloc] init];) \ | |
} \ | |
return sharedManager; \ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment