Hide instance variable from header file in Objective C

后端 未结 10 1069
梦如初夏
梦如初夏 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:58

    I was able to do the following in my library:

    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
    

    The protocol is optional of course. I believe this also makes all your instance variables private though I'm not 100% certain. For me it's just an interface to my static library so it doesn't really matter.

    Anyway, I hope this helps you out. To anyone else reading this, do let me know if this is bad in general or has any unforeseen consequences. I'm pretty new to Obj-C myself so I could always use the advice of the experienced.

提交回复
热议问题