Implement a pure virtual method in Objective-C

前端 未结 6 1542
清酒与你
清酒与你 2020-12-02 18:22

I want to go to there. Seriously though, how does one implement a pure virtual method in an \"Apple\" way? Do you use a Protocol with your base class and throw exceptions on

6条回答
  •  悲哀的现实
    2020-12-02 18:55

    Depending on what you're doing the delegate pattern may be more appropriate than a subclass, where the delegate is defined as id. The compiler will generate a warning if the required methods in the delegate protocol are not implemented.

    Subclassing is generally avoided in Objective-C since objects cannot inherit from multiple superclasses but they can implement multiple protocols.

提交回复
热议问题