Consider the following code snippets:
In .h:
typedef NS_OPTIONS(NSUInteger, ActionTrigger) {
bitmask0 = 1 << 0,
bitmask1 = 1 << 1,
...
};
@property (nonatomic) ActionTrigger notificationTrigger;
@property (nonatomic) BOOL actionNotificationPacketReceived;
In .m:
- (BOOL)actionNotificationPacketReceived {
return ((self.notificationTrigger & bitmask0) == bitmask0);
}
- (void)setActionNotificationPacketReceived:(BOOL)value {
if (value) {
self.notificationTrigger |= bitmask0;
} else {
self.notificationTrigger &= ~bitmask0;
}
}
Is it possible to replace the if/else statement in -setActionNotificationPacketReceived:
with pure boolean logic?
EDIT
I ended up using the following Macro, thanks to this answer.
#define OptionSetBool(option, flag, a_bool) ((a_bool) ? ((option) |= flag) : ((option) &= ~flag))