views:

24

answers:

1

I have a method that brings in an Enum value as an argument.

enum {
   UITableViewCellStateDefaultMask                     = 0,
   UITableViewCellStateShowingEditControlMask          = 1 << 0,
   UITableViewCellStateShowingDeleteConfirmationMask   = 1 << 1
}; 

There are four possible values:

  1. Only UITableViewCellStateDefaultMask is true.
  2. Only UITableViewCellStateShowingEditControlMask is true.
  3. Only UITableViewCellStateShowingDeleteConfirmationMask is ture.
  4. Both UITableViewCellStateShowingEditControlMask AND UITableViewCellStateShowingDeleteConfirmationMask are true.

That last possibility is the one I'm having trouble with. What statement will return true if and only if the two last options are true????

(This is Objective-C code btw)

Thanks!

+2  A: 
int mask=UITableViewCellStateShowingEditControlMask|UITableViewCellStateShowingDeleteConfirmationMask;
BOOL result=(value&mask)==mask;

or just

(value&0x03)==0x03

if you're feeling lazy :)

invariant