My understanding is that protocols are like interfaces in other languages — they declare expected methods — while categories allow you to add new methods to existing types (perhaps even types you don’t own.)
Why, then, does the iPhone SDK sometimes use categories for declaring delegate types? Normally I would expect all delegates to be typed id<MyDelegateProtocol> but there are many examples where this is not the case.
For example, see NSURLConnection. Its delegate is typed “id” and the ‘contract’ is declared as a category on NSObject (NSURLConnectionDelegate).
So: what’s the motivation for using categories in these cases?
Objective-C 2.0 introduced the @optional protocol directive, allowing you to declare certain protocol methods to be optional. Prior to Obj-C 2.0, categories were used to allow optional delegate methods (specifically, categories on NSObject, which are called informal protocols).
My guess is that most of the category-instead-of-protocol use in the iPhone SDK is a holdover from the equivalent Mac classes. For example,
NSURLConnectionexists in both the Mac and iPhone SDKs, so the code is likely shared. Since Apple hasn’t yet gone through to change all of the Mac classes to use formal protocols, we’re left with somewhat of an inconsistency.