IOS - Can't Use Super as a Link?

I am trying to use NSInvocation to call a superclass method from a subclass. The code used is relatively simple, it looks like this:

 - (NSInvocation*) invocationWithSelector:(SEL)selector { NSInvocation* call = [[NSInvocation alloc] init]; [call retainArguments]; call.target = super; //ERROR: use of undeclared identifier 'super' call.selector = @selector(selector); return call; } 

It seems to me that this is a bit strange, since I always thought that super adheres to almost the same rules as self (i.e. it can be considered as a direct reference to the object in question and assigned to variables, used as a return value, etc. ) This does not seem to be the case in practice.

Anyway, is there an easy way to get my NSInvocation aim at implementing a superclass (I can't use self as a target because the subclass overrides the methods of the superclass), or do I need to look for some other suitable ones?

+6
source share
2 answers

See What exactly is super in Objective-C? for more information, but super is not really an object. Super is a compiler keyword for generating obj-c runtime calls (specifically objc_msgSendSuper). Basically, it looks like you are sending your class to your superclass before sending a message to it.

EDIT So, if you have redefined the method you want to call, you will have to write another method to directly call [super method] and set your call to call this method. The runtime will only send messages to objects, and they will be processed at the lowest member of the inheritance chain that implements them.

+9
source

super and self are the same object, so just use

 call.target = self; 

The difference between the two is that you can use super as the recipient of the message for self to ensure that it invokes the implementation of the superclass.

+1
source

Source: https://habr.com/ru/post/915637/


All Articles