News for hackers. Stuff that matters.
Re:Objective-C Bitmask Enumeration Essentials by tonysuper on Friday May 23, 2014 @12:37PM (#7790063)
Isn't this applicable to any kind of bitmask, and not just Obj-C?

I suppose that Cocoa uses bitmasks fairly often, but this article could have been titled "Working With Bitmasks in C" and it would have been just as accurate.

Re:Objective-C Bitmask Enumeration Essentials by anon1385 on Friday May 23, 2014 @12:00PM (#7789895)
>Use the bitwise AND operator & to check for a selected bitmask enumeration value.

You should take care if you store result of this in a BOOL (or pass it to a method or function that takes a BOOL). BOOL is only char big and plenty of common Cocoa bitmasks don't have any bits set in that range. For example NSEventMaskEndGesture is (1<<20).

  NSEventMask mask = NSEventMaskEndGesture;
  BOOL end = mask & NSEventMaskEndGesture;
  if (!end) NSLog(@"Oops");
Re:Objective-C Bitmask Enumeration Essentials by MaxGabriel on Friday May 23, 2014 @12:11PM (#7789945)
Is this the correct approach?

    BOOL end = mask & NSEventMaskEndGesture ? YES : NO;
Re:Objective-C Bitmask Enumeration Essentials by plorkyeran on Friday May 23, 2014 @12:27PM (#7790013)
(mask & NSEventMaskEndGesture) == NSEventMaskEndGesture is the most correct, as it handles the case where NSEventMaskEndGesture has multiple bits set.
Re:Objective-C Bitmask Enumeration Essentials by ridiculous_fish on Friday May 23, 2014 @01:56PM (#7790453)
I think, not!!

   BOOL end = !! (mask & NSEventMaskEndGesture);
Like a little pair of surprised eyes.

Also works for pointers:

    BOOL hasError = !! errorObj;
Re:Objective-C Bitmask Enumeration Essentials by al_gore on Friday May 23, 2014 @12:26PM (#7790007)
or just != 0
Re:Objective-C Bitmask Enumeration Essentials by al_gore on Friday May 23, 2014 @12:27PM (#7790011)
This is just plain old C (which, yes, Objective-C is a superset of).