5

In UITableView.h, in the interface declaration for UITableView, there is an ivar struct _tableFlags. The struct's members are all defined as unsigned int, however the title of each member is followed by a colon and then a number.

struct {
    unsigned int dataSourceNumberOfRowsInSection:1;
    unsigned int dataSourceCellForRow:1;

    unsigned int longPressAutoscrollingActive:1;
    unsigned int adjustsRowHeightsForSectionLocation:1;
    unsigned int customSectionContentInsetSet:1;
} _tableFlags;

Cocoa tends to make common use of this syntax in its header files, but I've no clue what it means and what its function is. What does the colon and the number following the member title mean?

Daniyar
  • 2,975
  • 2
  • 26
  • 39
LinenIsGreat
  • 594
  • 4
  • 13
  • 3
    in Cocoa, bitfields are often used to cache respondsToSelector return values on a delegate. see here: http://macdevelopertips.com/c/bitfields-in-c.html and here: http://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c where it says " Instead of checking whether a delegate responds to a selector every time we want to message it, you can cache that information when delegates are set." – magma Jun 11 '12 at 02:39

1 Answers1

5

These are bit fields. The number after the colon is the number of bits the variable takes in the structure.

See also: how to declare an unsigned int in a C program

Community
  • 1
  • 1
mttrb
  • 8,297
  • 3
  • 35
  • 57
  • 2
    Ah, so the bit fields are used in order to make certain that the least amount of memory is used by the struct? Would it be correct to assume that BOOL wasn't used because it's defined as a signed char and therefore more than one bit wide? – LinenIsGreat Jun 11 '12 at 03:04