I have an enum holding several values:
enum {value1, value2, value3} myValue;
In a certain point in my app, I wish to check which value of
I will introduce is the way I use, and it looks better than previous answer.(I thinks)
I would like to illustrate with UIImageOrientation for easy understanding.
typedef enum {
UIImageOrientationUp = 0, // default orientation, set to 0 so that it always starts from 0
UIImageOrientationDown, // 180 deg rotation
UIImageOrientationLeft, // 90 deg CCW
UIImageOrientationRight, // 90 deg CW
UIImageOrientationUpMirrored, // as above but image mirrored along other axis. horizontal flip
UIImageOrientationDownMirrored, // horizontal flip
UIImageOrientationLeftMirrored, // vertical flip
UIImageOrientationRightMirrored, // vertical flip
} UIImageOrientation;
create a method like:
NSString *stringWithUIImageOrientation(UIImageOrientation input) {
NSArray *arr = @[
@"UIImageOrientationUp", // default orientation
@"UIImageOrientationDown", // 180 deg rotation
@"UIImageOrientationLeft", // 90 deg CCW
@"UIImageOrientationRight", // 90 deg CW
@"UIImageOrientationUpMirrored", // as above but image mirrored along other axis. horizontal flip
@"UIImageOrientationDownMirrored", // horizontal flip
@"UIImageOrientationLeftMirrored", // vertical flip
@"UIImageOrientationRightMirrored", // vertical flip
];
return (NSString *)[arr objectAtIndex:input];
}
All you have to do is :
name your function.
copy contents of enum and paste that between NSArray *arr = @[ and ]; return (NSString *)[arr objectAtIndex:input];
put some @ , " , and comma
PROFIT!!!!