Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of enums - convert to NSArray

Having

enum {MyA, MyB, Null};
typedef NSNumber myEnum;

Or

typedef enum {MyA, MyB, Null} myEnum;

1) How do I create an array

myEnum* myEnumTemp[] = {MyA, MyB};

Just gives "Implicit conversion of 'int' to NSNumber* is disallowed with ARC(ref. counting)

2) If you are able to create an array how to convert it to NSArray?

like image 561
Chris G. Avatar asked Jan 20 '12 12:01

Chris G.


1 Answers

In Obj C:

enumArray = @[@(enum1),@(enum2)];

In Swift:

enumArray = NSArray(objects: enum1.rawValue, enum2.rawValue);
like image 122
Gobi M Avatar answered Oct 09 '22 00:10

Gobi M