In Java, C++11 and some other languages you can specify that a method is intended to override another method from a base class or interface, if you then at a later point remove the method from the base class you get a compiler error. I use protocols with optional methods a lot and find that if I remove a method from there I have a tendency to forget to remove the code that implemented the method. This does not generate an error or a warning, thus creating a "dead" method.
Consider:
@protocol Prot <NSObject>
@optional
- (void)bar;
- (void)tempBar;
@end
@interface MyType : NSObject <Prot>
@end
@implementation MyType
- (void)bar { /**/ }
- (void)tempBar { /**/ }
@end
If I at one point remove tempBar
from the protocol, I would like to get at least a warning from tempBar
being implemented in MyType
.
Is there any way in Objective-C to specify that a method is expected to be an implementation of a protocol method?