Swift snippet #2 — Generic UITableView dequeue cell
Ritesh Gupta

Hi Ritesh, nice post btw.

You can also improve your method to not hardcode you identifier creating a protocol like:

protocol Identifyable {} 
extension Identifyable where Self: UIView {
static var identifier: String {
return String(describing: self)


extension UITableView {
func dequeueReusableCell<T: UITableViewCell>(for indexPath:IndexPath) -> T where T: Identifyable {
guard let cell = dequeueReusableCell(withIdentifier: T.identifier, for: indexPath) as? T else {
fatalError(“Could not dequeue cell with identifier: \(T.identifier)”)
return cell

Using this your identifier will be the class name

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.