Objective-c enum object to string

enums, objective-c

Solution

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;
}

Problem

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?

Original source

Related problems