Files
raspberry/iOS/Wallet/Sources/Common/Extension/CommonUITableView.swift
2022-05-27 20:21:01 +03:00

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 let _ = Bundle.main.path(forResource: cell._xibName, ofType: "nib") {
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
}
}