Domanda

I was looking at the UIViewController header in Xcode, and I saw something that I have never encountered before. It was located in a struct, so I assume it was a member variable, but the way it was assigned was new to me. Here shortened version (the struct is 47 lines).

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;

Could someone shed some light on what : does? Is it like the C++ variable declaration syntax (bool b(true);), or something completely different? Possibly some reference type such as * and &.

È stato utile?

Soluzione

The ':' allows assignment (and later reference) of individual bits, of the same (unsigned int).

appearState gets 2 bits,

Hence 'appearState' may contain values: 0, 1, 2 or 3 only.

isEditing gets 1 bit,

'isEditing' may contain values: 0 or 1 only.

...etc.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top