<<目标枚举中的运算符? [英] << operator in objective c enum?

查看:86
本文介绍了<<目标枚举中的运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找东西,进入这个枚举的是苹果的UITableViewCell.h.

I was looking for something and got in to this enum is apple UITableViewCell.h.

很抱歉,这很简单,但我想知道/好奇这是什么意思.

I am sorry if this is trivial but I wonder/curious what is the point of this.

我知道<<来自红宝石,但我不太了解这个枚举?

I know the << from ruby but I don't really understand this enum ?

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

谢谢

顺便说一句 发现它是学习编码的好方法,我每天尝试一次进入对象上at列表的头文件.

BTW Found it as a great way to learn coding, I am trying once in a day to get into the header files of at list on object.

Shani

推荐答案

这些是位字段标志.之所以使用它们,是因为您可以使用按位或运算符来组合它们.因此,例如,您可以像这样组合它们

These are bit-field flags. They are used because you can combine them using the bitwise-OR operator. So for example you can combine them like

(UITableViewCellStateShowingEditControlMask | UITableViewCellStateShowingDeleteConfirmationMask)

它们通过将一位设置为整数来工作.在此示例中,以二进制格式

They work by having one bit set in an integer. In this example, in binary,

UITableViewCellStateShowingEditControlMask        = 0000 0001
UITableViewCellStateShowingDeleteConfirmationMask = 0000 0010

将它们进行或"运算时,将产生0000 0011.然后,框架知道这两个标志都已设置.

When they are OR'ed together, they produce 0000 0011. The framework then knows that both of these flags are set.

<<运算符是左移.它移动二进制表示形式.所以1 << 1表示

The << operator is a left-shift. It shifts the binary representation. So 1 << 1 means

0000 0001 shifted left by one bit = 0000 0010

1 << 2等于0000 0100.

这篇关于&lt;&lt;目标枚举中的运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆