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;
We don't use strong for enum property in Objective-C because enums aren't objects so we can 't specify them as strong or weak.
Objective-C Language Enums Defining an enumtypedef NS_ENUM(NSUInteger, MyEnum) { MyEnumValueA = 0, MyEnumValueB = 5, MyEnumValueC = 10, }; You can also specify on the first value and all the following will use it with increment: typedef NS_ENUM(NSUInteger, MyEnum) { MyEnumValueA = 0, MyEnumValueB, MyEnumValueC, };
Yes, it's not a problem:
@property (nonatomic, assign) stackState yourIvar;
@property (nonatomic, assign) enum stackState stackStateVar;
Without 'enum' added, my unit tests kept showing errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With