Created
June 3, 2016 10:56
-
-
Save rock88/1224231601bc4560c4f67887420eabe7 to your computer and use it in GitHub Desktop.
Enum to NSString macro
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
#define BEGIN_DEFINE_TYPE(type) NSString* NSStringFrom##type(type var) { | |
#define DEFINE_TYPE_VALUE(value) if (var == value) return @#value; | |
#define END_DEFINE_TYPE() return @"Unknown type"; } | |
typedef NS_ENUM(NSInteger, MyType) { | |
MyTypeTest, | |
MyTypeAppstore, | |
MyTypeRelease | |
}; | |
BEGIN_DEFINE_TYPE(MyType) | |
DEFINE_TYPE_VALUE(MyTypeTest) | |
DEFINE_TYPE_VALUE(MyTypeAppstore) | |
DEFINE_TYPE_VALUE(MyTypeRelease) | |
END_DEFINE_TYPE() | |
NSLog(@"%@", NSStringFromMyType(MyTypeAppstore)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment