问题
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