Hide instance variable from header file in Objective C

declaration, header, instance-variables, objective-c, private

Solution

For 64 bit applications and iPhone applications (though not in the simulator), property synthesis is also capable of synthesizing the storage for an instance variable.

I.e. this works:

@interface MyClass : MySuperClass 
{ 
    //nothing here
}

@property (nonatomic, retain) MyObject *anObject;
@end

@implementation MyClass
@synthesize anObject;
@end

If you compile for 32 bit Mac OS X or the iPhone Simulator, the compiler will give an error.

Problem

I came across a library written in Objective C (I only have the header file and the .a binary). In the header file, it is like this: ``` @interface MyClass : MySuperClass { //nothing here } @property (nonatomic, retain) MyObject anObject; - (void)someMethod; ``` How can I achieve the same thing? If I try to declare a property without its corresponding ivar inside the interface's {}, the compiler will give me an error. Ultimately, I want to hide the internal structure of my class inside the .a, and just expose the necessary methods to the header file. How do I declare instance variables inside the .m? Categories don't allow me to add ivar, just methods.

Original source