Skip to content

Instantly share code, notes, and snippets.

@karlis
Created October 19, 2019 12:29
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 karlis/d3ef2f7fa7c601a6a0e400a4c4e6a1e9 to your computer and use it in GitHub Desktop.
Save karlis/d3ef2f7fa7c601a6a0e400a4c4e6a1e9 to your computer and use it in GitHub Desktop.
ReusableCell for easy dequeueing in UITableView.
/// ReusableCell for easy dequeueing in table views. Use UITableView.dequeueReusableCell().
protocol ReusableCell {
static var reuseIdentifier: String { get }
init()
}
extension UITableView {
/// Dequeues a ReusableCell or allocates a new ReusableCell.
func dequeueReusableCell<Cell: ReusableCell>() -> Cell {
return dequeueReusableCell(withIdentifier: Cell.reuseIdentifier) as? Cell ?? Cell()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment