ReusableKit icon indicating copy to clipboard operation
ReusableKit copied to clipboard

Create generic getAll methods to register cells.

Open anirudhamahale opened this issue 4 years ago • 0 comments

I am trying to build generic getAll method will which just return instances of Reusable cells. By creating that I don't have to register the cells manually I can just add it to the array and in the registerCellsFromReusable() it will be registered.

enum Reusable {
  static let listOptionTableCell = ReusableCell<ListOptionTableCell>(nibName: "ListOptionTableCell")
  static let seperatorTableCell = ReusableCell<SeperatorTableCell>(nibName: "SeperatorTableCell")
	
  static func getAll<T>() -> [ReusableCell<T>] where T : UITableViewCell {
    return [listOptionTableCell, seperatorTableCell]
  }
}

override func viewDidLoad() {
  super.viewDidLoad()
	
  registerCellsFromReusable()
}

private func registerCellsFromReusable() {
  Reusable.getAll().forEach { tableView.register($0) }
}

Cool stuff but I don't know why I am getting the below issue even though ListOptionTableCell & SeperatorTableCell inherits from UITableViewCell

enter image description here

anirudhamahale avatar Feb 23 '21 09:02 anirudhamahale