Informal Protocol In objective-C?

后端 未结 7 650
旧巷少年郎
旧巷少年郎 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:47

    Informal protocols are a way to add optional methods to an object by means of category.

    So one doubt may arise

    Will it become informal protocol if there are any optional methods on protocol itself?

    The answer is no.

    If the methods are declared in protocol and it is said to be conforming to a class without any usage of category then it's formal protocol.

    Note:

    Optional methods in protocol were introduced in objective c 2.0 so before that the purpose was achieved through informal protocol I.e by means of category.

    Category:

    It is a language level feature meant to be alternative for sub classing aka inheritance.

    I hope it sheds some lime light on this..

提交回复
热议问题