子类是否在Objective-C中继承其父类的协议?

时间:2022-06-01 17:00:10

Suppose I have a parent class that implements a protocol:

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

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

And then I make subclasses of it:

然后我创建它的子类:

@interface TennisViewController : GameViewController {
  ...
}

@interface SoccerViewController : GameViewController {
  ...
}

Do I have to include the GamePrizeDelegate also in the subclasses? Are the protocols inherited as well?

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

Thanks!

谢谢!

1 个解决方案

#1


29  

Referring to Apple's documentation: Your subclass does inherit the adoption of the protocol, so you don't have to adopt it again.

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

Conforming to a Protocol

符合协议

A class is said to conform to a formal protocol if it adopts the protocol or inherits from another class that adopts it. An instance of a class is said to conform to the same set of protocols its class conforms to.

如果一个类采用协议或从另一个采用它的类继承,则认为该类符合正式协议。据说一个类的实例符合其类符合的同一组协议。

#1


29  

Referring to Apple's documentation: Your subclass does inherit the adoption of the protocol, so you don't have to adopt it again.

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

Conforming to a Protocol

符合协议

A class is said to conform to a formal protocol if it adopts the protocol or inherits from another class that adopts it. An instance of a class is said to conform to the same set of protocols its class conforms to.

如果一个类采用协议或从另一个采用它的类继承,则认为该类符合正式协议。据说一个类的实例符合其类符合的同一组协议。