Array of enums - convert to NSArray

后端 未结 3 805
清酒与你
清酒与你 2021-01-17 12:32

Having

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

Or

typedef enum {MyA, MyB, Null} myEnum;

1) How do

3条回答
  •  借酒劲吻你
    2021-01-17 13:07

    Try to do it this way :

    typedef enum { MyA, MyB, Null } myEnum;
    

    Then, to create an array, wrap the numbers into NSNumbers objects :

    NSArray *a = [NSArray arrayWithObjects:[NSNumber numberWithInteger:MyA],
                                           [NSNumber numberWithInteger:MyB],
                                           nil];
    

提交回复
热议问题