Skip to content

Create generic getAll methods to register cells. #12

Description

@anirudhamahale

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions