On 28 Apr '08, at 5:00 PM, K. Darcy Otto wrote:
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.
If you really want a fully abstract method, use a category: @interface ClassA : NSObject { ... } ... @end @interface ClassA(Check) -(BOOL)optionalMethodToImplement; @endNow you don't have to implement that method in the base class, but the compiler will allow you to call it on any instance of ClassA. (Of course at runtime you'll get a message-not-understood exception if the subclass didn't implement the method.)
To see if an instance implements that method, call [self respondsToSelector: @selector(optionalMethodToImplement:)].
if ([self conformsToProtocol:@protocol(Check)]) [self optionalMethodToImplement]; }Problem #1: The compiler complains that ClassA may not respond to optionalMethodToImplement.
If you still want to do it this way, you can work around that problem by casting the receiver:
[(id<Check>)self optionalMethodToImplement];
—Jens
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ 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 [EMAIL PROTECTED]