I have:
@interface SuperClass : UIViewController <UITableViewDelegate,UITableViewDataSource>
And then
@interface SubClass : SuperClass
This SuperClass
does not have the required protocol methods implemented SubClass
one does.
Is it possible to prevent the warnings (saying SuperClass implementation is incomplete)?
Instead of implementing empty/nil methods in SuperClass
, can the @required warnings validation be made against SubClass
?
You might not declare protocol adoption in the superclass, but demand compliance in all subclasses. This can be done by implementing +initialize
in your superclass as follows:
+ (void)initialize
{
if (self != [SuperClass class] &&
![self conformsToProtocol:@protocol(UITableViewDelegate)])
{
@throw [NSException ...]
}
}
That way, whenever a subclass of SuperClass
is initialized, it will throw an exception if it doesn't conform to <UITableViewDelegate>
. This requires no further work after putting this in the superclass.
No, what you're asking for is essentially abstract classes, which don't exist in Objective-C.
Your best bet is to stub the methods in the base class to throw an exception of some kind.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With