Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create generic getAll methods to register cells. #12

Open
anirudhamahale opened this issue Feb 23, 2021 · 0 comments
Open

Create generic getAll methods to register cells. #12

anirudhamahale opened this issue Feb 23, 2021 · 0 comments

Comments

@anirudhamahale
Copy link

anirudhamahale commented Feb 23, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant