A category is an extension to the functionality of a class - it is an implementation of some methods:
@interface NSObject (MyCategory) - (void)doSomething; @end ... @implementation NSObject (MyCategory) - (void)doSomething {
A formal protocol is something completely different. If you are familiar with any other object-oriented language, then it looks like an interface (in Java, C ++, C #, etc.).
A protocol can be attached to any class implementation as follows:
@protocol MyProtocol @required - (void)doSomething; @optional - (void)doSomethingOptional; @end ... @interface MyClass : NSObject <MyProtocol> { } @end ... @implementation MyClass - (void)doSomething {
According to the documentation, informal protocols are categories of the NSObject class (I never used this approach):
@interface NSObject (MyInformalProtocol) - (void)doSomething; @end ... @implementation NSObject (MyInformalProtocol) - (void)doSomething {
source share