Informal Protocol In objective-C?

后端 未结 7 625
旧巷少年郎
旧巷少年郎 2020-11-28 03:55

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

相关标签:
7条回答
  • 2020-11-28 04:57

    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).

    0 讨论(0)
提交回复
热议问题