NS_OPTIONS matches

ios, objective-c

Solution

The correct way to check for this value is to first bitwise AND the values and then check for equality to the required value.

MyCellCorners cellCorners = MyCellCornerTopLeft | MyCellCornerTopRight;

if ((cellCorners & MyCellCornerTopLeft) == MyCellCornerTopLeft) {
    // top left corner set
}

The following reference explains why this is correct and provides other insights into enumerated types.

Reference: checking-for-a-value-in-a-bit-mask

Problem

I am trying to implement the following typedef ``` typedef NS_OPTIONS (NSInteger, MyCellCorners) { MyCellCornerTopLeft, MyCellCornerTopRight, MyCellCornerBottomLeft, MyCellCornerBottomRight, }; ``` and correctly assign a value with ``` MyCellCorners cellCorners = (MyCellCornerTopLeft | MyCellCornerTopRight); ``` when drawing my cell, how can I check which of the options match so I can correctly draw it.

Original source