Protocol inheritance in Objective C

前端 未结 2 642
暖寄归人
暖寄归人 2020-12-16 04:51

I\'ve got a project which has in it a protocol, a class implementing that protocol, and a subclass of the implementation class. This is our production application.

<
2条回答
  •  清酒与你
    2020-12-16 05:25

    There is no official language definition for Objective-C, but according to Apple:

    When a class adopts a protocol, it must implement the required methods the protocol declares, as mentioned earlier. In addition, it must conform to any protocols the adopted protocol incorporates. If an incorporated protocol incorporates still other protocols, the class must also conform to them. A class can conform to an incorporated protocol using either of these techniques:

    • Implementing the methods the protocol declares
    • Inheriting from a class that adopts the protocol and implements the methods

    However, reports are that GCC doesn't recognize that the property is in an incorporated protocol and is implemented in a superclass. You could change your compiler to Clang, which is reported to handle this in the specified manner, or you could just use @dynamic to tell the compiler that an implementation of the property will be provided at run time (in this case, by inheritance from the superclass).

提交回复
热议问题