On Tue, Aug 5, 2008 at 5:41 AM, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hello list
>
> My superclass (SuperSocket) provides a private method -close.
> My subclass overrides this private method as follows:
>
> - (void)close
> {
>        SEL closeSelector = @selector(close);

Note, for getting the selector that the current method was called
with, you can just use "_cmd":


>
>        if ([SuperSocket instancesRespondToSelector:closeSelector]) {
>                [super performSelector:closeSelector];  // seems to send to
> self
>        } else {
>                NSAssert (NO, @"SuperSocket no longer responds to close
> message.");
>        }
>
>        // subclass additional code
> }
>
> If I am not mistaken this code appears to send the close selector to the
> self object.

Correct.

> If [super performSelector:closeSelector] is replaced by [super close] then
> the super object receives the close message as expected.

Remember, there is no such thing as a "super object". "super" is just
a keyword that tells the compiler to skip searching the current class
for methods. It doesn't change which object the message is sent to.

> I know that [super respondsToSelector: closeSelector] is equivalent to [self
> respondsToSelector: closeSelector] as the methods tests the object as a
> whole (see NSObject Protocol Reference entry for respondsToSelector;);
> So is that the story here?

Correct.

> Or am I on the wrong page entirely.

If you *really* need to call [super close] without hard-coding the
message (i.e. using an arbitrary selector), you can get the method's
IMP and call that like a function:

void (*functionPointer)(id,SEL,...) = [SuperSocket
instanceMethodForSelector: _cmd];
functionPointer(self,_cmd);

-- 
Clark S. Cox III
[EMAIL PROTECTED]
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to