Can a category implement a protocol in Objective-C?

I have a category in NSDate, and it would be convenient if it could implement the previously created protocol. Is it possible? what is the correct syntax for this?

+80
objective-c cocoa protocols categories
Apr 28 '11 at 20:44
source share
1 answer

Yes it is possible. Syntax:

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

Here's the Apple documentation on the topic.

This can also be done with a class extension. I really like the private negotiation of delegate protocols. This hides implementation details of the fact that they are delegates of a class from the public interface and removes the dependency from the header.

+131
Apr 28 '11 at 20:50
source share



All Articles