Skip to content

Instantly share code, notes, and snippets.

@malcolmkmd
Last active September 20, 2017 06:46
Show Gist options
  • Save malcolmkmd/16e13b6bf7f54e123958e0a53d7a53ca to your computer and use it in GitHub Desktop.
Save malcolmkmd/16e13b6bf7f54e123958e0a53d7a53ca to your computer and use it in GitHub Desktop.
UITableview nibloadable
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