I guess the ideal solution is to use something like

[BaseClass superclass]

inside BaseClass, etc.

Christiaan

On 5 Aug 2007, at 8:03 PM, Adam R. Maxwell wrote:

> Interesting.  I haven't run across that one before, but this code
> demonstrates the problem if I understand correctly.  It's sort of
> unfortunate, since inserting another class in the hierarchy could
> break things.
>
> #import <Foundation/Foundation.h>
>
> @interface BaseClass : NSObject
> @end
>
> @interface SubClass : BaseClass
> @end
>
> @implementation BaseClass
>
> - (void)doSomething:(id)obj
> {
>      NSLog(@"%@ %@", self, NSStringFromSelector(_cmd));
>      if ([[self superclass] instancesRespondToSelector:_cmd])
>          [super doSomething:self];
> }
>
> @end
>
> @implementation SubClass
>
> - (void)doSomething:(id)obj
> {
>      NSLog(@"%@ %@", self, NSStringFromSelector(_cmd));
>      if ([[self superclass] instancesRespondToSelector:_cmd])
>          [super doSomething:self];
> }
>
> @end
>
> int main (int argc, char const *argv[])
> {
>      NSAutoreleasePool *pool = [NSAutoreleasePool new];
>      SubClass *obj = [SubClass new];
>      [obj doSomething:nil];
>
>      [pool release];
>      return 0;
> }
> On Aug 5, 2007, at 10:22, Christiaan Hofman wrote:
>
>> I actually just learned it the hard way.
>>
>> Look at Skim's SKSnapshotTableView : SKThumbnailTableView.
>>
>> If this class would call
>> [[self superclass] instancesRespondToSelector:@selector
>> (validateMenuItem:)]
>> inside the implementation of -validateMenuItem: in
>> SKThumbnailTableView (which is called indirectly) it checks its
>> superclass *at run time*, which is SKThumbnailTableView. So this
>> check returns YES, and happily calls
>> [super validateMenuItem:]. However this happens in
>> SKThumbnailTableView's implementation, so it calls its superclass *at
>> compile time* (which is what super does), which is NSTableView.
>>
>> The main point is: it sends the message to super, and the class for
>> super is determined at compile time, so it also better check the
>> class determined at compile time, and not at run time.
>>
>> Christiaan
>>
>> On 5 Aug 2007, at 6:59 PM, Adam R. Maxwell wrote:
>>
>>> Can you give a concrete example of when this would fail?  I'm not
>>> sure
>>> I see the problem.
>>>
>>> thanks,
>>> adam
>>>
>>> On Aug 5, 2007, at 09:36, [EMAIL PROTECTED] wrote:
>>>
>>>> Revision: 10884
>>>>         http://bibdesk.svn.sourceforge.net/bibdesk/?
>>>> rev=10884&view=rev
>>>> Author:   hofman
>>>> Date:     2007-08-05 09:36:16 -0700 (Sun, 05 Aug 2007)
>>>>
>>>> Log Message:
>>>> -----------
>>>> Hard code the superclass for checking wether super responds to a
>>>> selector, as the class of super is implicitly also hard coded.
>>>> Otherwise it may check the wrong (sub)class.
>>>>
>>>> Modified Paths:
>>>> --------------
>>>>   trunk/bibdesk/BDSKFileMatcher.m
>>>>   trunk/bibdesk/BDSKPreferenceController.m
>>>>   trunk/bibdesk/BDSKZoomableScrollView.m
>>>>   trunk/bibdesk/BibDocument.m
>>>>   trunk/bibdesk/BibPersonController.m
>>>>
>>>> Modified: trunk/bibdesk/BDSKFileMatcher.m
>>>> ===================================================================
>>>> --- trunk/bibdesk/BDSKFileMatcher.m        2007-08-05 13:29:04 UTC (rev
>>>> 10883)
>>>> +++ trunk/bibdesk/BDSKFileMatcher.m        2007-08-05 16:36:16 UTC (rev
>>>> 10884)
>>>> @@ -740,7 +740,7 @@
>>>>
>>>> - (void)awakeFromNib
>>>> {
>>>> -    if ([[self superclass] instancesRespondToSelector:_cmd])
>>>> +    if ([NSWindowController instancesRespondToSelector:_cmd])
>>>>        [super awakeFromNib];
>>>>
>>>>    // colors similar to Spotlight's window: darker blue at bottom,
>>>> lighter at top
>>>>
>>>> Modified: trunk/bibdesk/BDSKPreferenceController.m
>>>> ===================================================================
>>>> --- trunk/bibdesk/BDSKPreferenceController.m       2007-08-05 13:29:04  
>>>> UTC
>>>> (rev 10883)
>>>> +++ trunk/bibdesk/BDSKPreferenceController.m       2007-08-05 16:36:16  
>>>> UTC
>>>> (rev 10884)
>>>> @@ -103,7 +103,7 @@
>>>> - (void)awakeFromNib;
>>>> {
>>>>    // OAPreferenceController may implement this in future
>>>> -    if ([[self superclass] instancesRespondToSelector:_cmd])
>>>> +    if ([OAPreferenceController instancesRespondToSelector:_cmd])
>>>>        [super awakeFromNib];
>>>>
>>>>    NSWindow *theWindow = [self window];
>>>>
>>>> Modified: trunk/bibdesk/BDSKZoomableScrollView.m
>>>> ===================================================================
>>>> --- trunk/bibdesk/BDSKZoomableScrollView.m 2007-08-05 13:29:04 UTC
>>>> (rev 10883)
>>>> +++ trunk/bibdesk/BDSKZoomableScrollView.m 2007-08-05 16:36:16 UTC
>>>> (rev 10884)
>>>> @@ -237,7 +237,7 @@
>>>>        return [self canZoomOut];
>>>>    else if([menuItem action] == @selector(zoomToActualSize:))
>>>>        return [self canZoomToActualSize];
>>>> -    else if ([[self superclass] instancesRespondToSelector:_cmd])
>>>> +    else if ([NSScrollView instancesRespondToSelector:_cmd])
>>>>        return [super validateMenuItem:menuItem];
>>>>    return YES;
>>>> }
>>>>
>>>> Modified: trunk/bibdesk/BibDocument.m
>>>> ===================================================================
>>>> --- trunk/bibdesk/BibDocument.m    2007-08-05 13:29:04 UTC (rev 10883)
>>>> +++ trunk/bibdesk/BibDocument.m    2007-08-05 16:36:16 UTC (rev 10884)
>>>> @@ -802,7 +802,7 @@
>>>>    NSSet *typesWithEncoding = [NSSet
>>>> setWithObjects:BDSKBibTeXDocumentType, BDSKRISDocumentType,
>>>> BDSKMinimalBibTeXDocumentType, BDSKLTBDocumentType, nil];
>>>>    NSString *selectedType = [[sender selectedItem]
>>>> representedObject];
>>>>    [saveTextEncodingPopupButton setEnabled:[typesWithEncoding
>>>> containsObject:selectedType]];
>>>> -    if ([[self superclass]
>>>> instancesRespondToSelector:@selector(changeSaveType:)])
>>>> +    if ([NSDocument
>>>> instancesRespondToSelector:@selector(changeSaveType:)])
>>>>        [super changeSaveType:sender];
>>>> }
>>>>
>>>>
>>>> Modified: trunk/bibdesk/BibPersonController.m
>>>> ===================================================================
>>>> --- trunk/bibdesk/BibPersonController.m    2007-08-05 13:29:04 UTC  
>>>> (rev
>>>> 10883)
>>>> +++ trunk/bibdesk/BibPersonController.m    2007-08-05 16:36:16 UTC  
>>>> (rev
>>>> 10884)
>>>> @@ -86,7 +86,7 @@
>>>> }
>>>>
>>>> - (void)awakeFromNib{
>>>> -  if ([[self superclass]
>>>> instancesRespondToSelector:@selector(awakeFromNib)]){
>>>> +  if ([NSWindowController
>>>> instancesRespondToSelector:@selector(awakeFromNib)]){
>>>>        [super awakeFromNib];
>>>>    }
>>>>    
>>>>
>>>>
>>>> This was sent by the SourceForge.net collaborative development
>>>> platform, the world's largest Open Source development site.
>>>>
>>>> ------------------------------------------------------------------- 
>>>> --
>>>> ----
>>>> This SF.net email is sponsored by: Splunk Inc.
>>>> Still grepping through log files to find problems?  Stop.
>>>> Now Search log events and configuration files using AJAX and a
>>>> browser.
>>>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>>>> _______________________________________________
>>>> Bibdesk-commit mailing list
>>>> [EMAIL PROTECTED]
>>>> https://lists.sourceforge.net/lists/listinfo/bibdesk-commit
>>>
>>>
>>> -------------------------------------------------------------------- 
>>> --
>>> ---
>>> This SF.net email is sponsored by: Splunk Inc.
>>> Still grepping through log files to find problems?  Stop.
>>> Now Search log events and configuration files using AJAX and a
>>> browser.
>>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>>> _______________________________________________
>>> Bibdesk-develop mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/bibdesk-develop
>>
>>
>> --------------------------------------------------------------------- 
>> ----
>> This SF.net email is sponsored by: Splunk Inc.
>> Still grepping through log files to find problems?  Stop.
>> Now Search log events and configuration files using AJAX and a
>> browser.
>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>> _______________________________________________
>> Bibdesk-develop mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/bibdesk-develop
>
>
> ---------------------------------------------------------------------- 
> ---
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a  
> browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Bibdesk-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bibdesk-develop


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Bibdesk-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-develop

Reply via email to