Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding Delegate Methods when subclassing in Cocoa

Suppose I have a class Foo which declares a delegate protocol with 3 methods. I would like to subclass Foo into a class called Bar and completely override these methods.

Should I declare them in the subclass header again?

When I implement these 3 methods inside of Bar's delegate, do I have to take any precautions to make sure Foo's implementation will not be used?

like image 819
Andrew Lauer Barinov Avatar asked May 04 '26 09:05

Andrew Lauer Barinov


1 Answers

Should I declare them in the subclass header again?

That won't be necessary, as your Bar.h will import Foo.h and therefore know it conforms that protocol.

When I implement these 3 methods inside of Bar's delegate, do I have to take any precautions to make sure Foo's implementation will not be used?

The only precaution you need to take is to not call [super delegateMethod]; on your implementations, and you're good to go.

like image 69
Ismael Avatar answered May 06 '26 01:05

Ismael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!