When you declare designated initializers in ObjC the compiler warns if you don't override the superclasses designated initializer even if you don't need it.
I have a class named say, InputInformation. Now InputInformation has several properties related to input (of course). Now I have another class,which is a subclass of InputInformation say OutputResult. Now lets say I have a class call Brain:
@interface Brain : NSObject
//all kinds of stuff..
-(OutResult*)generateOutputFromInput:(InputInformation*)input;
@endI choose to make output result a subclass of InputInfo because it uses many, but not all of Input's properties.
Now the InputInformation class has a desginated initializer that takes a bunch of parameters. Output has a designated initializer. and in the OutputResult class InputInformation's designated initializer is marked not allowed, to prevent compiler warnings. So Output overrides input's designated initializer to force a crash just in case someone uses it incorrectly.
Now OutputResult's designated initializer must call its super classes designated initializer. There are parameters that shouldn't be nil if the object is an InputInformation object, but should be nil if the object is an OutputResult object. Calling super and passing nil into nonnull params generates warnings...is there a way for a subclass to override and change nonnull, nullable rules of its superclass? I want to get the warnings for Input objects, but I don't want them on OutResult objects.
No, you can't change the nullability rules of a superclass. There are problems going both ways by doing that.
If the super class declares a property nullable, and the subclass declares it nonnull, then a client assuming super class instances might try to set the property to nil, but the instance only expects non-nil values, and thus break the subclass' contract.
If the super class declares a property nonnull, and the subclass declare it nullable, then the subclass setting that value to nil might break logic in the super class that relies on the value being nonnull.