Objective-C : enum like Java (int values and many others for each enum)
Posted
by
Oliver
on Stack Overflow
See other posts from Stack Overflow
or by Oliver
Published on 2011-01-01T23:40:47Z
Indexed on
2011/01/01
23:54 UTC
Read the original article
Hit count: 301
In Java, you can make an enum having multiples values. In objective-C, this cannot be done easily. I've read many pages about this but I didn't found anything satisfying that would allow me to use enums by a simple way and to keep the enum declaration and their different values in the same file.
I would like to write something like this in a enums.h :
// ========================================
typedef enum {eRED, eGREEN, eBLUE} ColorEnum;
int colorValues[] = { 0xFF0000, 0x00FF00, 0x0000FF };
NSArray *colorNames = [NSArray arrayWithObjects:@"Red color", @"light green", @"Deep blue", nil];
// ========================================
and be able to use thoses global variables to manage my stuff anywhere like :
int color = colorValues[eRED];
But I don't know how to write this. I have compile errors like "ColorValues" is defines many times. Or if I just use "static", I have many "ColorValues" not used in .m file...
Could you help me ?
© Stack Overflow or respective owner