extension UITableView {
func registerCell<T: UITableViewCell>(type: T.Type) {
let className = type.className
let nib = UINib(nibName: className, bundle: nil)
registerNib(nib, forCellReuseIdentifier: className)
}
func registerCells<T: UITableViewCell>(types: [T.Type]) {
types.forEach { registerCell($0) }
}
func dequeueCell<T: UITableViewCell>(type: T.Type, indexPath: NSIndexPath) -> T {
return self.dequeueReusableCellWithIdentifier(type.className, forIndexPath: indexPath) as! T
}
}
tableView.registerCell(MyCell.self)
tableView.registerCells([MyCell1.self, MyCell2.self])
let cell = tableView.dequeueCell(MyCell.self)