Can't instantiate NSNumber with shorthand @n type syntax when using enum?

196 Views Asked by At

I have an enum defined like this:

typedef enum dataTypes{
    LOW,
    MEDIUM,
    HIGH,
    MAX_DATA_TYPE
} dataTypeEnum;

I'd like to be able to instantiate an NSArray of NSNumbers like so:

NSArray * numsToUse = @[@LOW, @MEDIUM];

This is not compiling. Any insights? Do I have to go with the clunkier [NSNumber numberWithInt:] for each of these or is there a way around this? (I have considered and rejected #define statements for a number of reasons).

1

There are 1 best solutions below

4
Rob Napier On BEST ANSWER

You just need to use the expression syntax:

NSArray * numsToUse = @[@(LOW), @(MEDIUM)];