Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if self.bitmask |= flag adds an option, how to remove one?

Tags:

Example

self.accessibilityTraits |= UIAccessibilityTraitAdjustable; 

adds the UIAccessibilityTraitAdjustable option. But how to remove an option from the mask like this, without having to set everything?

like image 804
openfrog Avatar asked Jul 26 '13 09:07

openfrog


2 Answers

And it with the complement of the flag:

self.accessibilityTraits &= ~UIAccessibilityTraitAdjustable; 

If self.accessibilityTraits was:

  000110 

and UIAccessibilityTraitAdjustable is:

  000100 

(these values are examples; I haven't looked-up the real values)

then self.accessibilityTraits &= ~UIAccessibilityTraitAdjustable; is:

  000110 & 111011 = 000010 
like image 181
trojanfoe Avatar answered Oct 13 '22 23:10

trojanfoe


Try self.accessibilityTraits &= ~UIAccessibilityTraitAdjustable;

~ inverts the bits therefor the bits to be retained are 1 now and the bits to be cleared are 0. ANDing it with the left hand side variable will retain the bits which has 1s in the corresponding locations of ~UIAccessibilityTraitAdjustable and will clear the bits which has 0s in the corresponding locations of ~UIAccessibilityTraitAdjustable.

like image 42
phoxis Avatar answered Oct 13 '22 21:10

phoxis