Expose a private Objective-C method or property to subclasses

后端 未结 7 1372
栀梦
栀梦 2020-12-05 06:43

According to some official talk, a class in Objective-C should only expose public methods and properties in its header:

@interface MyClass : NSObject

@prope         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 07:22

    While the other answers are correct, I'd like to add...

    Private, protected and public are available for instance variables as such:

    @interface MyClass : NSObject {
    @private
      int varA;
    
    @protected
      int varB;
    
    @public
      int varC;
    }
    
    @end
    

提交回复
热议问题