Skip to content

Instantly share code, notes, and snippets.

@unboxme
Created August 13, 2016 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unboxme/36bb5b1574a60ac0566240c6aa46a6a2 to your computer and use it in GitHub Desktop.
Save unboxme/36bb5b1574a60ac0566240c6aa46a6a2 to your computer and use it in GitHub Desktop.
Returns string from enum value
enum {
ObjectiveC = 'ObjC',
Java = 'Java',
Ruby = 'Ruby'
} Language;
- (NSString *)stringFromEnumValue:(NSUInteger)enumValue {
char *str = calloc(sizeof(enumValue) + 1, sizeof(char));
int integer = NSSwapInt((unsigned int) enumValue);
memcpy(str, (const void *) &integer, sizeof(integer));
NSString *stringValue = [NSString stringWithFormat:@"%s", str];
free(str);
return stringValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment