Why UITableView cells can’t have a custom init?
When it comes to custom tableView cells there are 2 ways to init them:
- awakeFromNib() — Init from a XIB file
- init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) — Init in code
We might think of adding another init with some dependencies to set up the cell’s view components but then we won’t be able to re-use the cell in the tableView. To be able to register a cell to be reused we have to use one of the default initializations, if we want to configure the cell, we will have to add a separate method to do that!
Even if we were able to add a custom init, we might run into some issues as the init for a cell is called only once and then it might be reused. So the custom setup we intended to do for the cell, will never happen when its reused!