Search code examples
objective-caccess-modifiersprivate-members

Objective-C Access @private instance variables from another class


I've been looking at this question and came across the following code in one of the answers

@interface MyClass : NSObject
{
    @private
    int someVar;  // Can only be accessed by instances of MyClass

    @public
    int aPublicVar;  // Can be accessed by any object
}
@end

Is there anyway to access someVar from any other class (including derived classes)?


Solution

  • As with most dynamic languages you can get at this information in Objective C, however, it is painful. Look here for an example.