【问题标题】:Does a subclass inherit the protocols of its parent class in Objective-C?子类是否继承了 Objective-C 中其父类的协议?
【发布时间】:2011-08-28 20:27:02
【问题描述】:

假设我有一个实现协议的父类:

@interface GameViewController : UIViewController<GamePrizeDelegate> {
  ...
}

然后我创建它的子类:

@interface TennisViewController : GameViewController {
  ...
}

@interface SoccerViewController : GameViewController {
  ...
}

我是否必须在子类中也包含GamePrizeDelegate?协议是否也继承?

谢谢!

【问题讨论】:

    标签: objective-c inheritance protocols


    【解决方案1】:

    参考Apple's documentation:您的子类确实继承了协议的采用,因此您不必再次采用它。

    Conforming to a Protocol

    一个类被称为符合一个正式的 协议,如果它采用协议或 从另一个类继承 采用它。一个类的实例是 据说符合同一套 其类所遵循的协议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 2021-09-04
      • 2011-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-28
      相关资源
      最近更新 更多