Created
August 13, 2016 12:03
-
-
Save unboxme/36bb5b1574a60ac0566240c6aa46a6a2 to your computer and use it in GitHub Desktop.
Returns string from enum value
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
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