Can a category implement a protocol in Objective C? Can a category implement a protocol in Objective C? objective-c objective-c

Can a category implement a protocol in Objective C?


Yes, that's possible. The syntax is:

@interface NSDate (CategoryName) <ProtocolName>@end@implementation NSDate (CategoryName)@end

Here's Apple's documentation on the topic.

It's also possible to do this using a class extension. I very much like this to privately conform to delegate protocols. Doing so hides the implementation detail of being some delegate of some class from the public interface and removes the dependency from the header.