Possible Duplicate:
Convert objective-c typedef to its string equivalent
I have an enum declared as followed:
typedef enum MODE {
FRAMED, HALFPAGED, FULLPAGED
} MODE;
Is there any way to convert the FRAMED/HALFPAGED/FULLPAGED to a string.
I know C++ has the ability by using:
static String^ GetName(
Type^ enumType,
Object^ value
)
Would there be an equivalent for Objective-C?
You can implement a method like this:
- (NSString*)modeToString:(MODE)mode{
NSString *result = nil;
switch(mode) {
case FRAMED:
result = @"FRAMED";
break;
case HALFPAGED:
result = @"HALFPAGED";
break;
case FULLPAGED:
result = @"FULLPAGED";
break;
default:
[NSException raise:NSGenericException format:@"Unexpected MODE."];
}
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With