Re: subclass says "unrecognized selector"
Re: subclass says "unrecognized selector"
- Subject: Re: subclass says "unrecognized selector"
- From: Kyle Sluder <email@hidden>
- Date: Sat, 12 Feb 2011 12:03:09 -0800
On Sat, Feb 12, 2011 at 5:52 AM, Mikkel Eide Eriksen
<email@hidden> wrote:
> 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:
It doesn't look like your code doesn't require any instance
information at all. I'd probably implement it as a class method:
+ (NSDictionary *)tagDict {
NSMutableDictionary *tags = GetTagsFromPlistForClass(self);
if ([super respondsToSelector:@selector(tagDict)])
[tags addEntriesFromDictionary:[super tagDict]];
return [[tags copy] autorelease];
}
Or you can be even more robust and use a protocol, that way if an
ancestor class happens to implement a method named -tagDict that is
unrelated to your intended meaning, you don't suffer from a collision.
(If you're not writing a framework, this is probably overkill).
@protocol TagDictProtocol
+ (NSDictionary *)tagDict;
@end
@interface SuperClass : NSObject <TagDictProtocol>
@end
@implementation SuperClass
+ (NSDictionary *)tagDict {
NSMutableDictionary *tags = GetTagsFromPlistForClass(self);
if ([super conformsToProtocol:@protocol(TagDictProtocol)])
[tags addEntriesFromDictionary:[super tagDict]];
return [[tags copy] autorelease];
}
@end
--Kyle Sluder
_______________________________________________
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