AFAIK, Swift does not allow using the metatype as a generic type. (I think this is similar to what Sam Giddins wished for in Swift 3. )
. , T
, :
protocol SomeProtocol {
static func foo()
}
struct Concrete: SomeProtocol {
static func foo() {
print("I am concrete")
}
}
class SomeClass {
let T: SomeProtocol.Type
init(T: SomeProtocol.Type) {
self.T = T
}
func go() {
T.foo()
}
}
SomeClass(T: Concrete.self).go()
, , , . , , :
class SomeClass<U: SomeProtocol> {
let T: U.Type
init(T: U.Type) {
self.T = T
}
func go(value: U) {
T.foo()
}
}
SomeClass(T: Concrete.self).go(Concrete())