Accessing Private ivars in ASOC and Objective-C

I wanted to change the initial focus in an NSDatePicker to the day instead of the month as you get by default. Searching around on the web, I found that NSDatePickerCell has a private ivar, _indexOfSelectedSubfield, which can be used to change the focus in ASOC like so:

set picker's |cell|()'s _indexOfSelectedSubfield to 2

This works fine, but I’m writing this app in Objective-C, and I can’t get it to work there. I keep getting compiler errors that the ivar is private. Why does this work in ASOC? Should not the ivar be unavailable there too? Is there something about the bridge that gets around the @private directive, and if so, is this general? And, is there a different way to accomplish this task in Objective-C?



the ObjC equivalent is

[[picker cell] _selectNextSubfield];

But consider that this method is undocumented.


How did you find this method, I didn’t see it in the .h file?



private methods could be declared also in the .m file

But aren’t the .m files unpublished, or do these things leak out?


there is a objc-sel-table and there are lots of geeks having fun to investigate the APIs :wink: