Expose a private Objective-C method or property to subclasses

后端 未结 7 1325
栀梦
栀梦 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:06

    Your only choice is to declare it as public in the header file. If you want to at least keep some method separation, you can create a category and have all your protected methods and attributes there, but in the end everything will still be public.

    #import "MyClass.h"
    
    @interface MyClass (Protected)
    
    - (void) protectedMethods;
    
    @end
    

提交回复
热议问题