You are perhaps looking for a way to simply loop through all of the options? How about just a plan old normal array?
typedef enum {RED,BLUE,GREEN,YELLOW} color;
color colors[4]={RED,YELLOW,GREEN,BLUE};
for (int i=0;i<4;i++)
colors[i];
On the other hand if performance isn't an issue and you are just looking to clean up the code a little; how about creating a class ColorArray that encapsulates NSMutableArray and creates the relevant methods.
ColorArray.h:
#import <Foundation/Foundation.h>
typedef enum {RED,BLUE,GREEN,YELLOW} Color;
@interface ColorArray : NSObject {
NSMutableArray* _array;
}
- (id) initWithArray:(Color[])colors;
- (void) addColor:(Color)color;
- (Color) colorAtIndex:(int)i;
@end
ColorArray.c:
#import "ColorArray.h"
@implementation ColorArray
- (id) init {
if (self = [super init]) {
_array = [[NSMutableArray alloc] init];
}
return self;
}
- (id) initWithArray:(Color[])colors {
if (self = [super init]) {
_array = [[NSMutableArray alloc] init];
for (int i=0;colors[i]!=0;i++)
[_array addObject:[NSNumber numberWithInt:colors[i]]];
}
return self;
}
- (void) dealloc {
[_array release];
[super dealloc];
}
- (void) addColor:(Color)color {
[_array addObject:[NSNumber numberWithInt:color]];
}
- (Color) colorAtIndex:(int)i {
return [[_array objectAtIndex:i] intValue];
}
@end