Can a category simultaneously implement a protocol?

Viewed 7787

If a category I'm creating for a class adds methods that also fulfill the contract set out by a protocol, I'd like to flag that category class as implementing the protocol, and thereby indicate to the Obj-C pre-processor that the class effectively implements the protocol as well.

Example delegate (for clarity, thanks Ole!):

@protocol SomeDelegate <NSObject>
  - (void)someDelegateMessage;
@end

Example category:

@interface NSObject (SomeCategory) <SomeDelegate>
  - (void)someDelegateMessage;    
@end

And with an otherwise typical implementation

@implement NSObject (SomeCategory)
  - (void)someDelegateMessage {}
@end

When I actually try this, I get a warning for each NSObject method:

warning: incomplete implementation of category 'SomeCategory'

warning: method definition for '-description' not found

...

warning: method definition for '-isEqual:' not found

warning: category 'SomeCategory' does not fully implement the 'NSObject' protocol

Works fine if I remove <SomeDelegate> from the declaration, but of course NSObject isn't recognized as a SomeDelegate

3 Answers
Related