Skip to content

Instantly share code, notes, and snippets.

@AlexPinhasov
Created July 1, 2020 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexPinhasov/1b5caabeb1c50cda4caf063b188a3b44 to your computer and use it in GitHub Desktop.
Save AlexPinhasov/1b5caabeb1c50cda4caf063b188a3b44 to your computer and use it in GitHub Desktop.
class TableViewCellGenerator<T: UITableViewCell> {
// Class func - We need to override since each cell uses different objects to populate it self
class func configure(cell: UITableViewCell, using object: Any?, at indexPath: IndexPath) {}
// Static func - Should not be overriden since we use generics here
static func cell(for indexPath: IndexPath, inTableView tableView: UITableView) -> UITableViewCell {
return tableView.dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath)
}
static func registerReuseIdentifier(for tableView: UITableView) {
tableView.register(T.nibName, forCellReuseIdentifier: T.reuseIdentifier)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment