Search code examples
objective-cinheritanceprotocols

Does a subclass inherit the protocols of its parent class in Objective-C?


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?

Thanks!


Solution

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

    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.