":"分配整数的运算符

时间:2014-05-05 03:49:52

标签: objective-c c integer

我正在查看Xcode中的UIViewController标题,我看到了以前从未遇到过的内容。它位于struct,所以我认为它是一个成员变量,但它的分配方式对我来说是新的。这里缩短版本(struct是47行)。

struct {
    unsigned int appearState:2;
    unsigned int isEditing:1;
    unsigned int isPerformingModalTransition:1;
    unsigned int hidesBottomBarWhenPushed:1;
    unsigned int autoresizesArchivedViewToFullSize:1;
    // many more : assignments
} _viewControllerFlags;

有人可以了解:的作用吗?它是否像C ++变量声明语法(bool b(true);),或者完全不同的东西?可能是某种引用类型,例如*&

1 个答案:

答案 0 :(得分:2)

':'允许对相同的(unsigned int)的各个位进行赋值(以及后来的引用)。

appearState gets 2 bits,

因此'appearState'可能包含值:仅限0,1,2或3。

isEditing gets 1 bit,

'isEditing'可能包含值:0或1。

...etc.
相关问题