bursyllac
bursyllac

Reputation: 413

Can I use an enum as a property in Objective C

I saw it is customed to use a boolean property as a flag. something like that:

@property (nonatomic) BOOL commaAlreadyIntroduced;

I need something like that but with at least 3 or 4 states.

Can I use an enum?

The standalone enum should look like:

typedef enum stackState{
    empty, oneOperand, operandAndOperator, fullStack
}stackState;

Upvotes: 31

Views: 22699

Answers (3)

Arvin Sanmuga Rajah
Arvin Sanmuga Rajah

Reputation: 520

@property (nonatomic, assign) enum stackState stackStateVar;

Without 'enum' added, my unit tests kept showing errors.

Upvotes: 8

Pfitz
Pfitz

Reputation: 7344

Yes, it's not a problem:

@property (nonatomic, assign) stackState yourIvar;

Upvotes: 63

FishStix
FishStix

Reputation: 5114

@property (nonatomic, assign) enum stackState yourIvar;

(was getting errors until I added enum)

Upvotes: 3

Related Questions