objective-c - ios , 关于多 参数 枚举 的实现?
漂亮男人
漂亮男人 2017-05-02 09:19:11
0
1
684

我想实现 可以 传入 多参数枚举值的方法,例如

,请教一下,方法里面的逻辑判断

漂亮男人
漂亮男人

reply all(1)
阿神

The UIRectCornerTopLeft and UIRectCornerTopRight shown in your code are actually not enumerations, but 按位掩码(bitmask), and their definition is as follows:

typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
    UIRectCornerTopLeft     = 1 << 0,
    UIRectCornerTopRight    = 1 << 1,
    UIRectCornerBottomLeft  = 1 << 2,
    UIRectCornerBottomRight = 1 << 3,
    UIRectCornerAllCorners  = ~0UL
};

The syntax of a bitwise mask (NS_OPTIONS) is the same as an enumeration (NS_ENUM), but the compiler will combine its values ​​| through a bitmask.

Editor:

For example, for the NS_OPTIONS of UIRectCorner above, according to your code, what you pass in is UIRectCornerTopLeft | UIRectCornerTopRight , then the processing code is roughly as follows:

UIRectCorner myRectCornerOptions = UIRectCornerTopLeft | UIRectCornerTopRight; // 你在方法里接收到值应该是这个。

// 对传入的 NS_OPTIONS 的处理逻辑:
if (myRectCornerOptions & UIRectCornerTopLeft) {
    // 包含了 UIRectCornerTopLeft。
} else {
    // 未包含 UIRectCornerTopLeft。
}
    
if (myRectCornerOptions & UIRectCornerTopRight) {
    // 包含了 UIRectCornerTopRight。
} else {
    // 未包含 UIRectCornerTopRight。
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!