Last active
December 15, 2015 22:09
-
-
Save uliwitness/5330743 to your computer and use it in GitHub Desktop.
Macro-based implementation of objects as constants for Objective C. Could probably write code that auto-generates all the OCONSTANTI(a) macro calls based on the OCONSTANT(a) macros. But that wouldn't work for system headers.
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 <Foundation/Foundation.h> | |
#define PASTE(a,b) a ## b | |
#define OCONSTANT(a) @class a; extern a* PASTE(k,a); @interface a : NSObject @end | |
#define OCONSTANTI(a) @class a; a* PASTE(k,a) = nil; @implementation a +(void) load { PASTE(k,a) = [[a alloc] init]; } @end | |
OCONSTANT(ULIConstantOne) // For .h file. | |
OCONSTANTI(ULIConstantOne) // For .m file. | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
// insert code here... | |
NSLog(@"%@!", kULIConstantOne); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment