0
votes

When you subclass a class with a designated initializer (say, initWithNibName:bundle: a subclass of UIViewController), and need to provide your own designated initializer, the Big Nerd Ranch book says to provide your own designated initializer and override the designated initializer of the superclass to call your own new designated initializer. But what do you do if the extra parameters are required?

Concretely, something like this:

@interface MyViewController : UIViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil
                         bundle:(NSBundle *)nibBundleOrNil
                     andDummyObj:(DummyObj*)p
                   withDelegate:(id<DummyObjEditDelegate>)delegate;

@end

I guess the point of overriding the superclass delegate is to configure my subclass correctly if it's unarchived from a nib file ? But if someone calls the superclass designated initializer they won't be able to provide the delegate, and I need that to be correctly set.

Thanks.

1

1 Answers

0
votes

You should document the requirements of using the class, and if you require the parameters then you should throw an exception if they aren't provided (which should always be picked up during development).