Skip to content

Instantly share code, notes, and snippets.

@StanislavK
Created February 11, 2018 12:08
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 StanislavK/1248fdaffd68c14f22416af8f6032010 to your computer and use it in GitHub Desktop.
Save StanislavK/1248fdaffd68c14f22416af8f6032010 to your computer and use it in GitHub Desktop.
import UIKit
extension UITableView {
func register<T: UITableViewCell>(_: T.Type) {
let nib = UINib(nibName: T.nibName, bundle: nil)
register(nib, forCellReuseIdentifier: T.reuseIdentifier)
}
func dequeueReusableCell<T: UITableViewCell>(forIndexPath indexPath: IndexPath) -> T {
guard let cell = dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as? T else {
fatalError("Could not dequeue cell with identifier: \(T.reuseIdentifier)")
}
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment