29 lines
1.0 KiB
Swift
29 lines
1.0 KiB
Swift
//
|
|
// UITableView+Extensions.swift
|
|
// OpenSourceControllerDemo
|
|
//
|
|
// Created by Florian Gabach on 10/12/2018.
|
|
// Copyright © 2018 OpenSourceController. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension UITableView {
|
|
open func register<T: UITableViewCell>(cellType: T.Type)
|
|
where T: Reusable {
|
|
self.register(cellType.self, forCellReuseIdentifier: cellType.reuseIdentifier)
|
|
}
|
|
|
|
open func dequeueReusableCell<T: UITableViewCell>(for indexPath: IndexPath, cellType: T.Type = T.self) -> T
|
|
where T: Reusable {
|
|
guard let cell = self.dequeueReusableCell(withIdentifier: cellType.reuseIdentifier, for: indexPath) as? T else {
|
|
fatalError(
|
|
"Failed to dequeue a cell with identifier \(cellType.reuseIdentifier) matching type \(cellType.self). "
|
|
+ "Check that the reuseIdentifier is set properly in your XIB/Storyboard "
|
|
+ "and that you registered the cell beforehand"
|
|
)
|
|
}
|
|
return cell
|
|
}
|
|
}
|