I am trying to define a identifier (class name) static computed variable on a UITableViewCell extension and access the identifier by sending a subclass to a generic function.
When accessing the Subclass.identifier, I get the name of the subclass, but when accessing it from a generic function, it returns UITableViewCell
code:
protocol Identifiable {
static var identifier: String { get }
}
extension Identifiable {
static var identifier: String { return String(describing: Self.self) }
}
extension UITableViewCell: Identifiable { }
class Subclass: UITableViewCell {
}
print("\(Subclass.identifier)") // Output: "Subclass"
func blah<T: Identifiable>(_ cellType: T.Type) {
print("\(cellType.identifier)")
}
blah(Subclass.self) // Output: "UITableViewCell"
How can I get the Subclass identifier in the generic function without having to conform to the Identifiable protocol on all of my UITableView subclasses?