Reputation: 3573
I know that one should not overide a method in a category.
I wonder if the following is possible. Experts in Objective-C are welcomed to answer!
I have two parent/child classes : Class : ParentClass
For each class, I have a category : ParentClass(Category)
and Class(Category)
In each of these category, I have a method -(void)additionalMethod
. The methods have the same name and are defined in the category (they don't exist in the classes)
Upvotes: 1
Views: 489
Reputation: 539745
From "Customizing Existing Classes" in the "Programming with Objective-C" guide:
At runtime, there’s no difference between a method added by a category and one that is implemented by the original class.
So the answer to your question is YES. There is no difference between overriding a method in the subclass itself or in a category of the subclass. It makes also no difference if the overridden method is implemented in the base class itself or in a category of the base class.
The only thing you cannot do is to use a category to override a method of the same class or of another category of the class.
Upvotes: 3