This may seem strange, but I would like to do the following:
Class A
- (void)someMethod;
Class B : A
- (void)someMethod; // overrides
Class C : B
- (void)someMethod; // overrides
In class C, I would like to override a method present in the two super classes, but call only Class A's method on a [super methodName] call.
- (void)someMethod
{
[super someMethod]; // but I want to call class A, not B
}
Possible?
Private methods of the super-class cannot be called. Only public and protected methods can be called by the super keyword. It is also used by class constructors to invoke constructors of its parent class.
Definition and Usage The super keyword refers to superclass (parent) objects. It is used to call superclass methods, and to access the superclass constructor. The most common use of the super keyword is to eliminate the confusion between superclasses and subclasses that have methods with the same name.
Use of super() to access superclass constructor As we know, when an object of a class is created, its default constructor is automatically called. To explicitly call the superclass constructor from the subclass constructor, we use super() .
The super keyword in Java is a reference variable that is used to refer parent class objects. The super() in Java is a reference variable that is used to refer parent class constructors. super can be used to call parent class' variables and methods. super() can be used to call parent class' constructors only.
Something like this should work:
// in Class C:
#import <objc/runtime.h>
- (void)someMethod
{
// I want to call class A's implementation of this method
IMP method = class_getMethodImplementation([ClassA class], _cmd);
method(self, _cmd);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With