Make a type itself — not its instances — conform to a protocol

跟風遠走 提交于 2020-01-12 18:51:49

问题


I was wondering if it is possible in Swift to make a type conform to a protocol, so that I can treat the type itself as conforming to a protocol the way one normally treats instances as conforming to a protocol. Example code:

protocol P {
    func f()
}

class C where C.self: P { // Not actual code
    static func f() {
        print("Because C.f: ()->() exists, C.self should satisfy the protocol.")
    }
}

来源:https://stackoverflow.com/questions/42286462/make-a-type-itself-not-its-instances-conform-to-a-protocol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!