Re: super respondsToSelector
Re: super respondsToSelector
- Subject: Re: super respondsToSelector
- From: "stephen joseph butler" <email@hidden>
- Date: Sat, 31 May 2008 01:38:29 -0500
On Sat, May 31, 2008 at 1:22 AM, Russ McBride <email@hidden> wrote:
> It seems like either an infinite loop should occur if respondsToSelector is
> really being called on self, or it should return NO if it's called on super,
> in which case my delegate method in self should never get called.
If you called respondsToSelector: on self inside of your
respondsToSelector:, then yeah, that would be an infinite loop
condition. Otherwise, calling respondsToSelector: on super should work
like any other overridden method.
The respondsToSelector: implementation in NSObject looks at the method
table for the current class, not just the methods that are defined in
NSObject. Perhaps that's where your confusion comes from. From the
documentation:
<file://localhost/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/doc/uid/20000052-BBCEHCCE>
"You cannot test whether an object inherits a method from its
superclass by sending respondsToSelector: to the object using the
super keyword. This method will still be testing the object as a
whole, not just the superclass's implementation. Therefore, sending
respondsToSelector: to super is equivalent to sending it to self.
Instead, you must invoke the NSObject class method
instancesRespondToSelector: directly on the object's superclass, as
illustrated in the following code fragment."
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden