I was wondering if someone can explain what is informal protocols in Objective C? I try to understand it on apple documentation and some other books but my head is still spi
All an informal protocol is is a category on some class (often NSObject
) that states the interface for the protocol. AppKit uses this a lot for its delegation.
A subclass that you write can implement these methods. The difference between this and a formal protocol is that formal protocols are declared using the @protocol ... @end
notation. There is no checking whether a class implements a given informal protocol.
I almost always use formal protocols, but I suppose an informal protocol is useful if you want to provide default behavior (just provide an implementation for your category that can be overridden).