Created
May 6, 2013 09:49
-
-
Save robb/5524258 to your computer and use it in GitHub Desktop.
Convenience macro for creating singletons and the like. Handy if you define a lot of fixture objects.
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
#define SHARED_INSTANCE(EXPR) \ | |
^(){ \ | |
static typeof((EXPR)) instance; \ | |
static dispatch_once_t onceToken; \ | |
dispatch_once(&onceToken, ^{ \ | |
instance = EXPR;\ | |
});\ | |
return instance;\ | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use it like so