I like the idea of abstracting CellControllers in a heterogeneous UITableView as suggested by Matt Gallagher. However in the case of typical push-detail-view behavior, I find myself creating nearly-identical variants of LinkRowCellController
that differ only by the detail view controllers' init
methods -- init:
, initWithBook:
, initWithMagazine:
, initWithHelpURLString:andTopic:
, etc.
It seems like I could change the designated initializer to take a dictionary of property keys and initial arguments and have the LinkRowCellController
initWithProperties:
method set up the properties using setValueForKey:
on the pairs passed in.
That solution seems to give up compile-time checking of the init
arguments. What is the best practice in Objective-C for heterogeneous inits in otherwise homogeneous code?
UPDATE:
Based on jlehr's answer below I implemented a superclass with a single method initWithDictionary:(NSDictionary *)dict
that everything inherits from:
- (id)initWithDictionary:(NSDictionary *)dict
{
if ((self = [super init]) != nil)
{
for (id key in dict) {
[self setValue:[dict objectForKey:key] forKey:key];
}
}
return self;
}