Having
enum {MyA, MyB, Null};
typedef NSNumber myEnum;
Or
typedef enum {MyA, MyB, Null} myEnum;
1) How do
Basically, you need to wrap the value in a NSNumber object.
#define INT_OBJ(x) [NSNumber numberWithInt:x]
[array addObject:INT_OBJ(MyA)];
And there was nothing wrong with your other array, you just should have defined it like this:
typedef enum {MyA, MyB, Null} myEnum;
myEnum values[] = { MyA, MyB };
The problem was that you defined myEnum as a NSNumber
, which is not equal to an enum value (int).
In Obj C:
enumArray = @[@(enum1),@(enum2)];
In Swift:
enumArray = NSArray(objects: enum1.rawValue, enum2.rawValue);
Try to do it this way :
typedef enum { MyA, MyB, Null } myEnum;
Then, to create an array, wrap the numbers into NSNumber
s objects :
NSArray *a = [NSArray arrayWithObjects:[NSNumber numberWithInteger:MyA],
[NSNumber numberWithInteger:MyB],
nil];