Accessing a method in a super class when it's not exposed

前端 未结 3 1385
孤城傲影
孤城傲影 2020-12-16 12:59

In a subclass, I\'m overriding a method that is not exposed in the super class. I know that I have the correct signature as it is successfully overriding the superclass imp

3条回答
  •  执笔经年
    2020-12-16 13:09

    One way to go is to create a category of your class in a separate file with the method you are trying to expose

    @interface MyClass (ProtectedMethods)
    
    - (void)myMethod;
    
    @end
    

    and on the .m

    @implementation MyClass (ProtectedMethods)
    
    - (void)myMethod {
    
    }
    
    @end
    

    Then, import this category from your .m files, and you're good to go. It's not the prettiest thing, but it'll do the trick

提交回复
热议问题