Unexpected result from -[super respondsToSelector:]
Unexpected result from -[super respondsToSelector:]
- Subject: Unexpected result from -[super respondsToSelector:]
- From: Jerry Krinock <email@hidden>
- Date: Fri, 15 Feb 2008 22:03:35 -0800
I've subclassed NSTextView in order to customize its drag destination
behavior. In so doing, I needed to over-ride awakeFromNib in order to
run a little patch. I then dutifully tried to give super a chance to
do its thing...
@implementation SSDragDestinationTextView : NSTextView
- (void)awakeFromNib {
[self patchPreLeopardFocusRingDrawingForScrolling] ;
if ([super respondsToSelector:@selector(awakeFromNib)]) {
NSLog(@"super DOES respond to awakeFromNib") ;
[super awakeFromNib] ;
NSLog(@"It worked.") ;
}
}
...
The above code gives me this head-scratchin' console output:
super DOES respond to awakeFromNib
*** -[SSDragDestinationTextView awakeFromNib]:
unrecognized selector sent to instance 0x14c56f30
I believe that the reference in the exception to
"SSDragDestinationTextView" is an anomoly/bug/artifact in Cocoa's
exception logging. There is no actual instance of 'super'. The
object is really 'self', so that's the class that it prints. I
believe what it means to say is that NSTextView does not respond to -
awakeFromNib.
But what's more surprising is that -respondsToSelector doesn't work as
expected when sent to super. It looks like, if you're dealing with an
informal protocol like NSNibAwaking, for which the documentation does
not state which classes conform to, you've just got to try it and see
if you get an exception, then hard-code accordingly.
_______________________________________________
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