Re: subclass says "unrecognized selector"
Re: subclass says "unrecognized selector"
- Subject: Re: subclass says "unrecognized selector"
- From: claw <email@hidden>
- Date: Sat, 12 Feb 2011 15:54:20 +0100
hi,
why not try something like :
if ( [self isKindOfClass:[SuperClass class] ] )
{
}
so your test will not depend on instance but on 'typeof'
usually in code you use 'super' to verify that some data in 'super' already exist or need to be initialised between testing super & self
Le 12 févr. 2011 à 14:52, Mikkel Eide Eriksen a écrit :
> 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 (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
_______________________________________________
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