If you define your enum so that the values โโhave mutually exclusive bit patterns, for example:
typedef enum : NSUInteger { kMessageTypeLoveLetter = 1 << 0, kMessageTypeBirthdayCard = 1 << 1, kMessageTypeVacationPostcard = 1 << 2, kMessageTypeCreditApplication = 1 << 3, kMessageTypeCharitySolicitation = 1 << 4 } MessageType;
Then you can check multiple values โโat once using binary OR | and binary AND & :
MessageType msgType = kMessageTypeCreditApplication; if( !(msgType & (kMessageTypeLoveLetter | kMessageTypeBirthdayCard)) ){
However, this will not work if you use compiler-generated sequential values โโfor enum , because the values โโwill overlap flags, for example, both 2 and 3 have the lowest bit, and together they often finish testing only one of the flags.
source share