In my class I have a generic initializer:
- (id)initWithSettings:(MySettings *)settings
{
self = [super init];
if (self)
{
/// ...
}
return self;
}
And it has another initialiser with fixed setting
- (id)initWithSettingsForCaseA
{
return [self initWithSettings:[MySettings genericSettings]];
}
Can I do this?
Of course you can!
This is actually a good practice.
initWithSettings: is called the “designated initializer”. There’s no programmatic way of defining the designated initializer. This is more of a design pattern/best practice.
Take for instance the designated initializer for a UIViewController, initWithNibName:bundle:..you can still call plain ol’ init and everything will work just fine as long as your nib is named the same as your view controller subclass. UIViewController simply calls its designated initializer and passes nil for both parameters.
You’re essentially doing the same thing!