Skip to content

Instantly share code, notes, and snippets.

@BeauNouvelle
Created April 11, 2019 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeauNouvelle/0d18cb0fd861ba0442abb6894c0c6c56 to your computer and use it in GitHub Desktop.
Save BeauNouvelle/0d18cb0fd861ba0442abb6894c0c6c56 to your computer and use it in GitHub Desktop.
extension UITableView {
public func dequeue<T: UITableViewCell>(cellClass: T.Type) -> T? {
return dequeueReusableCell(withIdentifier: cellClass.reuseIdentifier) as? T
}
public func dequeue<T: UITableViewCell>(cellClass: T.Type, forIndexPath indexPath: IndexPath) -> T {
guard let cell = dequeueReusableCell(
withIdentifier: cellClass.reuseIdentifier, for: indexPath) as? T else {
fatalError(
"Error: cell with id: \(cellClass.reuseIdentifier) for indexPath: \(indexPath) is not \(T.self)")
}
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment