How to store enum values in a NSMutableArray

Posted by Oysio on Stack Overflow See other posts from Stack Overflow or by Oysio
Published on 2010-03-21T15:30:43Z Indexed on 2010/03/21 15:31 UTC
Read the original article Hit count: 253

Filed under:
|
|

My problem is since an enum in objective-c essentially is an int value, I am not able to store it in a NSMutableArray. Apparently NSMutableArray won't take any c-date types like an int.

Is there any common way to achieve this ?

typedef enum 
{
    green,
    blue,
    red

} MyColors;


NSMutableArray *list = [[NSMutableArray alloc] initWithObjects:
                             green,
                             blue,
                             red,
                             nil];

//Get enum value back out
MyColors greenColor = [list objectAtIndex:0];

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about objective-c