Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created August 8, 2013 14:34
Show Gist options
  • Save fjolnir/6185128 to your computer and use it in GitHub Desktop.
Save fjolnir/6185128 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#define AN_ENUM \
MEMBER(foo) \
MEMBER(bar)
typedef enum {
#define MEMBER(name) name,
AN_ENUM
#undef MEMBER
} AnEnum;
NSString *AnEnumToString(AnEnum value)
{
#define MEMBER(name) if(value == name) return @( #name );
AN_ENUM
#undef MEMBER
return nil;
}
int main(void)
{
NSLog(@"%@", AnEnumToString(foo));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment