How to adopt a superclass's protocol?
How to adopt a superclass's protocol?
- Subject: How to adopt a superclass's protocol?
- From: "K. Darcy Otto" <email@hidden>
- Date: Mon, 28 Apr 2008 17:00:30 -0700
I need to have a subclass optionally extend a method already in the
superclass. After some research, my best guess is that an optionally
defined protocol is the best way to go about this. So, what I have in
the superclass is:
@interface ClassA : NSObject
{
...
}
...
@end
@protocol Check
@optional
-(BOOL)optionalMethodToImplement;
@end
Now, I don't want the superclass to implement it, so when it comes to
the actual method that needs to be extended, I do the following:
-(BOOL)checkMethod
{
... stuff ...
if ([self conformsToProtocol:@protocol(Check)])
[self optionalMethodToImplement];
}
Problem #1: The compiler complains that ClassA may not respond to
optionalMethodToImplement. Then I have:
@interface ClassB : ClassA
{
...
}
...
@end
@interface ClassB (private) <Check>
-(BOOL)optionalMethodToImplement;
@end
Problem #2: The compiler cannot find the protocol in the superclass.
I realise I could do the same thing by having a dummy method in the
superclass, and override that in the subclass. And I'm about to head
down that path; but it seems like there should be a way to do this
with protocols. Thanks in advance.
_______________________________________________
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