Created
March 28, 2017 05:37
-
-
Save feighter09/500e2f84f58702faa02956d8e7b01482 to your computer and use it in GitHub Desktop.
Make tableviews a bit safer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol CellType { | |
static var identifier: String { get } | |
} | |
extension CellType { | |
static var identifier: String { return "\(Self.self)" } | |
} | |
extension UITableView { | |
func register<Cell>(forReuse cell: Cell.Type) | |
where Cell: CellType, Cell: UITableViewCell | |
{ | |
register(Cell.self, forCellReuseIdentifier: Cell.identifier) | |
} | |
func dequeueReusable<Cell>(_ cellType: Cell.Type, for indexPath: IndexPath) -> Cell? | |
where Cell: CellType, Cell: UITableViewCell | |
{ | |
return dequeueReusableCell(withIdentifier: Cell.identifier, for: indexPath) as? Cell | |
} | |
} | |
extension StoryCell: CellType {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment