helloB
helloB

Reputation: 3582

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

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).

Upvotes: 2

Views: 198

Answers (1)

Rob Napier
Rob Napier

Reputation: 299265

You just need to use the expression syntax:

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

Upvotes: 5

Related Questions