I study some basics of informal protocols and real protocols. What confuses me is that Cocoa seems to be using a lot of unofficial protocols for NSObject. These informal protocols are categories in NSObject that declare methods but do not actually implement them.
As far as I understand, the only reason they use informal protocols (in other words, categories in NSObject that don't provide method implementations) is to provide auto-complete hints in Xcode.
One example is the -awakeFromNib method defined in NSNibLoading.h, which is an unofficial protocol for NSObject. The nib boot system checks at runtime if an object implements this method. If so, then it causes it.
But now imagine that there was no function called an unofficial protocol. An alternative that would have the same effect would be a real @protocol declaration that declares the optional -awakeFromNib method. NSObject will simply accept this protocol, and the compiler will happily provide autocomplete.
Can anyone point out the big difference between the two strategies? I don't see the point in unofficial protocols, but really would like to do that.
source
share