3
これは孤立した例なので、あまり役に立たないように見えるかもしれませんが、とにかく、なぜうまくいかないのでしょうか?どんな洞察も高く評価されました。Swift Generics(タイプ置換?)
protocol Prot: class {
init()
}
class A: Prot {
required init(){ }
}
struct Client<T: Prot> {
let tau: T.Type
}
if let aTau = A.self as? Prot.Type {
print(aTau === A.self) // ✅
Client(tau: A.self) // ✅
Client(tau: aTau) // ❌
}
エラーは次のとおりです。
Cannot invoke initializer for type 'Client<_>' with an argument list of type '(tau: Prot.Type)'
これは[プロトコルはそれ自体に準拠していませんか?](http://stackoverflow.com/questions/33112559/protocol-doesnt-conform-to-itself)の変形です。あなたは 'Prot'を'Prot'に準拠した型です。 – Hamish