N
Size: a a a
N
NU
DK
N
TestCell: UITableViewCell, Reusable {}
class MultipleTypeCellProvider {
var cellType:
Any.Type = TestCell.
self
}
class Test {
func test() {
let tableView = UITableView(frame: .zero)
let cellProvider = MultipleTypeCellProvider()
if
let multipleTypeCastedCellType = cellProvider.cellType
as? (UITableViewCell & Reusable).Type {
tableView.test_dequeueReusableCell(multipleTypeCastedCellType)
}
}
}
extension UITableView {
func test_dequeueReusableCell<C: UITableViewCell>(
_ cellType: C.Type) -> C?
where C: Reusable {
return dequeueReusableCell(withIdentifier: C.reuseIdentifier)
as? C
}
}
N
N
protocol Reusable {
static
var reuseIdentifier: String {
get }
}
public
extension Reusable {
static
var reuseIdentifier: String {
return String(describing:
self)
}
}
EM
FM
EM
TestCell: UITableViewCell, Reusable {}
class MultipleTypeCellProvider {
var cellType:
Any.Type = TestCell.
self
}
class Test {
func test() {
let tableView = UITableView(frame: .zero)
let cellProvider = MultipleTypeCellProvider()
if
let multipleTypeCastedCellType = cellProvider.cellType
as? (UITableViewCell & Reusable).Type {
tableView.test_dequeueReusableCell(multipleTypeCastedCellType)
}
}
}
extension UITableView {
func test_dequeueReusableCell<C: UITableViewCell>(
_ cellType: C.Type) -> C?
where C: Reusable {
return dequeueReusableCell(withIdentifier: C.reuseIdentifier)
as? C
}
}
N
EM
if let multipleTypeCastedCellType = cellProvider.cellType as? ... вот там
EM
N
EM
EM
NU
EM
N
DK