获取实现协议 swift 的 class 类型

Get the class type that implements a protocol swift

所以我想做的是让我可以轻松地在一个 tableView 上实现许多自定义 UITableViewCells,为此我想创建一个有助于填写功能的协议:

- (void)registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier

到目前为止我的协议是这样的:

protocol TableViewCellClassReportingProtocol: class {
    func reuseID() -> String
}

extension TableViewCellClassReportingProtocol {
    static func classObject() -> AnyClass? {
        return self.class
    }
}

但是我在获取 class 类型时遇到了问题,甚至认为我指定此协议必须由 class 实现。任何建议,我可能以错误的方式接近这个

所以这接近正确的答案,让我详细说明并感谢 Charles A。

dynamicType 是答案的一部分!很棒的电话!

函数的含义也必须改变,因为子类化和静态真正意味着 "class final"

覆盖点必须是

override class func reuseID() -> String