Objective-C : enum like Java (int values and many others for each enum)
- by Oliver
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 ?