Skip to content

Instantly share code, notes, and snippets.

protocol ObjectInfoable: NSObjectProtocol {}
extension ObjectInfoable {
static var fileName: String {
return String(describing: Self.self)
}
}
extension ObjectInfoable where Self: UIView {
static var nibName: UINib {
protocol TableViewCellGeneratorProtocol {
static func cell(for indexPath: IndexPath, inTableView tableView: UITableView) -> UITableViewCell
static func configure(cell: UITableViewCell, using object: Any?, at indexPath: IndexPath)
static func registerReuseIdentifier(for tableView: UITableView)
}
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)
}