I'm using multiple instances of an object creating a form:
{...
BPFormInputTextFieldCell *nameCell = [[inputTextFieldClass alloc] init];
nameCell.backgroundColor = cellBgnd;
nameCell.textField.placeholder = @"business_name";
nameCell.mandatory = YES;
nameCell.textField.delegate = self;
nameCell.customCellHeight = 40.0f;
BPFormInputTextFieldCell *addressCell = [[inputTextFieldClass alloc] init];
addressCell.backgroundColor = cellBgnd;
addressCell.textField.placeholder = @"contact_name";
addressCell.mandatory = YES;
addressCell.textField.delegate = self;
addressCell.customCellHeight = 40.0f;
BPFormInputTextFieldCell *dobCell = [[inputTextFieldClass alloc] init];
dobCell.backgroundColor = cellBgnd;
dobCell.textField.placeholder = @"address";
dobCell.mandatory = YES;
dobCell.textField.delegate = self;
dobCell.customCellHeight = 40.0f;
BPFormInputTextFieldCell *sexCell = [[inputTextFieldClass alloc] init];
sexCell.backgroundColor = cellBgnd;
sexCell.textField.placeholder = @"city";
sexCell.mandatory = YES;
sexCell.textField.delegate = self;
sexCell.customCellHeight = 40.0f;
BPFormInputTextFieldCell *contexturaCell = [[inputTextFieldClass alloc] init];
contexturaCell.backgroundColor = cellBgnd;
contexturaCell.textField.placeholder = @"region";
contexturaCell.mandatory = YES;
contexturaCell.textField.delegate = self;
contexturaCell.customCellHeight = 40.0f;
self.formCells = @[@[nameCell, addressCell, dobCell, sexCell, contexturaCell, pesoCell, estaturaCell, actividadCell, deseoCell, cuantosKilosCell, cuantoTiempoCell, ...];
...}
As you can see, I need to refactor this badly. The objects should also go into the array. What is the best approach?
BPFormInputTextFieldCell
your own subclass? Why not just move all of the redundant code to the initialization and pass in the textfield placeholder to the initializer? \$\endgroup\$...
sections... but I'm posting an answer anyway. \$\endgroup\$