// // UITableView.swift // List // // Created by Igor Danich on 30.06.2020. // Copyright © 2020 Igor Danich. All rights reserved. // import UIKit extension UITableViewCell { fileprivate static var _cellId: String { String(describing: self) } fileprivate static var _xibName: String { String(describing: self).components(separatedBy: ".").last! } } extension UITableView { func register(cell: T.Type, identifier: String? = nil) { if let _ = Bundle.main.path(forResource: cell._xibName, ofType: "nib") { register(UINib(nibName: cell._xibName, bundle: nil), forCellReuseIdentifier: identifier ?? cell._cellId) } else { register(cell, forCellReuseIdentifier: identifier ?? cell._cellId) } } func dequeueReusableCell(_ type: T.Type, indexPath: IndexPath, identifier: String? = nil) -> T { // swiftlint:disable force_cast dequeueReusableCell(withIdentifier: identifier ?? T._cellId, for: indexPath) as! T } }