Each class must have a designated initializer; one true version of the init... method, which must always be called in order to properly initialize the class (like Matt states).
However, this does not completely solve the problem in that the class can also support instantiation through unarchival, which runs in the same “where I posed the problem with general initialization” in your question.
As a rule, I create a method such as:
- (void)commonInit { ... common initialization goop goes here ... }
And then first call it from the designated initializers and / or initWithCoder:
Yes, a little messy, but little can be done about it.
General clutter reduction strategy:
• provide very few initializers; perhaps init + one initializer with all possible arguments for other configurations.
• Assign the super initializer as the DI and execute any additional initializers through it. When subclassing where you have a more specific DI (see UIView initWithFrame: , override super DI to call [self initFancy:...] , which then calls [super initThroughSupersDI] .
bbum
source share