29 lines
1.0 KiB
Swift
29 lines
1.0 KiB
Swift
//
|
|
// UITableView.swift
|
|
// List
|
|
//
|
|
// Created by Igor Danich on 30.06.2020.
|
|
// Copyright © 2020 Igor Danich. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension UITableViewCell {
|
|
fileprivate static var _cellId: String { String(describing: self) }
|
|
fileprivate static var _xibName: String { String(describing: self).components(separatedBy: ".").last! }
|
|
}
|
|
|
|
extension UITableView {
|
|
func register<T: UITableViewCell>(cell: T.Type, identifier: String? = nil) {
|
|
if Bundle.main.path(forResource: cell._xibName, ofType: "nib") != nil {
|
|
register(UINib(nibName: cell._xibName, bundle: nil), forCellReuseIdentifier: identifier ?? cell._cellId)
|
|
} else {
|
|
register(cell, forCellReuseIdentifier: identifier ?? cell._cellId)
|
|
}
|
|
}
|
|
func dequeueReusableCell<T: UITableViewCell>(_ type: T.Type, indexPath: IndexPath, identifier: String? = nil) -> T {
|
|
// swiftlint:disable force_cast
|
|
dequeueReusableCell(withIdentifier: identifier ?? T._cellId, for: indexPath) as! T
|
|
}
|
|
}
|