Re: How to adopt a superclass's protocol?
Re: How to adopt a superclass's protocol?
- Subject: Re: How to adopt a superclass's protocol?
- From: Michael Vannorsdel <email@hidden>
- Date: Tue, 29 Apr 2008 16:00:38 -0600
Sounds like you're getting into a mess of includes. I know you'd like
to use a protocol but honestly the cleanest way to do this is not to
use a protocol but implement the optional methods in the subclasses
without listing them in the header. Then in the superclass method
just check if it responds to that selector and call it with
performSelector (or objc_msgSend if multiple args; the compiler turns
messages into this anyways). The compiler won't complain and the
runtime will handle everything more cleanly. Protocols are mostly for
requiring methods to be implemented by a class so a calling object can
be sure all the methods needed are there. Protocols can lead to a
mess when you want some methods implemented, some not, and hidden
methods.
On Apr 29, 2008, at 2:40 PM, K. Darcy Otto wrote:
The casting worked, and the protocol gets found; but I'm still
getting a warning that the protocol is not found. Here's what I have:
Superclass.h:
@protocol Check;
Superclass.m:
@protocol Check
@optional
-(BOOL)optionalMethodToImplement;
@end
(I'm relegating the protocol to the .m file to make it "private" in
a sense.)
Subclass.h
@interface Subclass : Superclass <Check>
...
Now, the compiler issues a warning at the @interface line in
Subclass.h - "no definition of protocol 'Check' is found". But it
is clear that the protocol is being located at runtime nevertheless,
because if I eliminate <Check> from the @interface line,
optionalMethodToImplement: does not get called. Also, what is
interesting is that if I move @protocol Check ... @end in
Superclass.m to Superclass.h, the warning goes away. So, is there a
way to keep @protocol Check ... @end in Superclass.m and eliminate
the warning?
_______________________________________________
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