Hide instance variable from header file in Objective C

后端 未结 10 1042
梦如初夏
梦如初夏 2020-12-30 14:35

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 : MyS         


        
10条回答
  •  执念已碎
    2020-12-30 14:51

    I don't think the following code written in another answer is working as expected. The "SomeClass *someVars" defined in the extension class is not an instance variable of MyClass. I think it is a C global variable. If you synthesize someVars, you will get compile error. And self.someVars won't work either.

    myLib.h

    @interface MyClass : SomeSuperClass  {
        // Nothing in here
    }
    
    - (void)someMethods;
    @end
    

    myLib.m

    @interface MyClass () 
        SomeClass *someVars;
    
        @property (nonatomic, retain) SomeClass *someVars;
    @end
    
    @implementation MyClass
    
    @synthesize someVar;
    
    - (void)someMethods {
    }
    @end
    

提交回复
热议问题