31

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;
bursyllac
  • 413
  • 1
  • 5
  • 11

3 Answers3

63

Yes, it's not a problem:

@property (nonatomic, assign) stackState yourIvar;
Sebyddd
  • 4,305
  • 2
  • 39
  • 43
Pfitz
  • 7,336
  • 4
  • 38
  • 51
8
@property (nonatomic, assign) enum stackState stackStateVar;

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

3

@property (nonatomic, assign) enum stackState yourIvar;

(was getting errors until I added enum)

FishStix
  • 4,994
  • 9
  • 38
  • 53