super is relative to the class where this code is implemented (SuperClass) 
which means the method lookup starts with the super class of SuperClass. This 
true even when the code is called from a subclass.
You're getting the "unrecognized selector sent to instance" message because the 
super class of SuperClass does not implement the tagDict method.

Regards,
Thomas

On 12 févr. 2011, at 14:52, Mikkel Eide Eriksen wrote:

> Hi all,
> 
> I think I may have misunderstood something about how super works. In trying 
> to build a dictionary that contains key/value pairs from the class itself as 
> well as super classes up to an arbitrary height, I've hit a wall. Simplified, 
> I have two classes, SuperClass and SubClass. In SuperClass, the following 
> method is implemented:
> 
> -(NSDictionary *)tagDict
> {
>       NSMutableDictionary *dict = //built from plist, different for each class
>       if ([self class] == [SuperClass class]) {
>               return dict; // we don't go above our own root
>       }
>       
>       NSEnumerator *keyE = [[super tagDict] keyEnumerator]; //HERE
>       id key;
>       
>       while (key = [keyE nextObject]) {
>               [dict setValue:[[super tagDict] valueForKey:key]];
>       }
>       
>       return [dict copy];
> }
> 
> When this runs, it works fine if I call tagDict on an instance of SuperClass, 
> but if I try with SubClass, I get:
> 
> -[SubClass tagDict]: unrecognized selector sent to instance 0x20038efe0
> 
> But shouldn't it keep calling upwards until I reach the SuperClass, then stop 
> and return my finished dict? I see that it appears to be calling [SubClass 
> tagDict] which is the very method it's already in (so the selector can't very 
> well be unrecognized, or what?)...
> 
> Regards,
> Mikkel_______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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/tclementdev%40gmail.com
> 
> This email sent to tclement...@gmail.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to