Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 20, 2010, 05:47 PM   #1
CMT
macrumors member
 
Join Date: Aug 2009
Structs declared in @interface

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

Code:
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)

Thanks!
CMT is offline   0 Reply With Quote
Old Sep 20, 2010, 05:57 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Look up "bit fields" in a C language reference doc.

Quote:
2.How can I then access this struct from inside object: _TvFlags.(~) or _TvFlags->(~) (dereferenced)
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:
Code:
 /*All instance variables are private*/

Last edited by chown33; Sep 20, 2010 at 06:04 PM.
chown33 is offline   0 Reply With Quote
Old Sep 20, 2010, 06:20 PM   #3
CMT
Thread Starter
macrumors member
 
Join Date: Aug 2009
Quote:
Originally Posted by chown33 View Post
Look up "bit fields" in a C language reference doc.
Thanks. I had never learned about it (beginner programmer)

Quote:
That doesn't make syntactical sense. _TvFlags is a typedef.
Indeed. Sorry, I mean to use the struct itself like you concluded.

Quote:
I'm not even sure what you intend (~) to mean.
Means "something".

Quote:
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.
Ok, thanks for the comparison which clarified things.

Quote:
And you'd do well to heed this comment from NSTableView.h:
Code:
 /*All instance variables are private*/
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.
CMT is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Pashua gui tool interface elements anything similar in xcode interface builder wild4life2013 Mac Programming 1 Aug 10, 2013 08:13 PM
Internet Cafes Declared Illegal in Ohio IGregory Politics, Religion, Social Issues 39 May 29, 2013 03:02 PM
Structs and Functions or Classes and Methods? ArtOfWarfare iPhone/iPad Programming 6 Mar 21, 2013 08:27 PM
arrays of structs farmerdoug Mac Programming 3 Feb 7, 2013 01:47 PM
Structs and Enum problems nashyo iPhone/iPad Programming 5 Sep 9, 2012 01:19 PM

Forum Jump

All times are GMT -5. The time now is 01:23 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps