Structs declared in @interface

Discussion in 'Mac Programming' started by CMT, Sep 20, 2010.

  1. CMT
    Expand Collapse
    macrumors member


    Aug 24, 2009
    Many headers from Apple, line the NSTableView, have structs declared containing flags:

    typedef struct __TvFlags {
        unsigned int        allowsColumnReordering:1;
        unsigned int        allowsColumnResizing:1;
        unsigned int        oldDrawsGridFlag:1;
        unsigned int        allowsEmptySelection:1;
        unsigned int        allowsMultipleSelection:1;
        unsigned int        allowsColumnSelection:1;
        unsigned int        selectionType:2;
        unsigned int        changingLayout:1; // Unused
        unsigned int        compareWidthWithSuperview:2;
        unsigned int        delegateWillDisplayCell:1;
        unsigned int        delegateShouldEditTableColumn:1;
        unsigned int        delegateShouldSelectRow:1;
        unsigned int        delegateShouldSelectTableColumn:1;
        unsigned int        delegateSelectionShouldChangeInTableView:1;
        unsigned int        oldAutoresizesAllColumnsToFit:1;
        unsigned int        dataSourceSetObjectValue:1;
        unsigned int        selectionPostingDisableCount:7;
    } _TvFlags;
    This brings me 2 questions:

    1.What is this ":1" (or ":2") at the end of each line? I've never seen this!
    2.How can I then access this struct from inside object: _TvFlags.(~) or _TvFlags->(~) (dereferenced)

  2. chown33
    Expand Collapse
    macrumors 604

    Aug 9, 2009
    Look up "bit fields" in a C language reference doc.

    That doesn't make syntactical sense. _TvFlags is a typedef. You wouldn't use uint_32.(~). I'm not even sure what you intend (~) to mean.

    If your question is, "How do I access the bit fields of the _tvFlags member variable, whose type is _TvFlags?", then the answer can be obtained by looking up "bit fields" in a C language reference doc. The short answer is: the same way you'd access any other member of any other struct. Since NSSize or NSRect is also a typedef'ed struct, consider how you'd access its members.

    And you'd do well to heed this comment from NSTableView.h:
     /*All instance variables are private*/
  3. CMT
    Expand Collapse
    thread starter macrumors member


    Aug 24, 2009
    Thanks. I had never learned about it (beginner programmer)

    Indeed. Sorry, I mean to use the struct itself like you concluded.

    Means "something".

    Ok, thanks for the comparison which clarified things.

    I know they are private, and I do not intent to use this struct, just pointed it out. I will be using these struct's to flags in my classes.

    Thank you chown33, everything is clear now.

Share This Page