If I override a class method, is there a way I can call the original method (the one that was overridden)?

前端 未结 3 1873
清酒与你
清酒与你 2021-01-03 13:53

In Objective-C, if I override a class method using a category, is there a way I can call the original method (the one that was overridden)?

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 14:48

    http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html

    Doesn't look like it is possible.

    When a category overrides an inherited method, the method in the category can, as usual, invoke the inherited implementation via a message to super. However, if a category overrides a method that already existed in the category's class, there is no way to invoke the original implementation.

    What this is saying to me is that if you override a method on a subclass via a category, you can call [super methodName] as you would normally, but if you override the base class method directly, you can't invoke the original.

提交回复
热议问题