次のコードはSwift 3.2で動作するようになっていますが、Swift 4の最新リリースでは私は理解できません。汎用プロトコルSwift 4エラー
私はそうのような汎用的なプロトコルを作成しようとしています:
public protocol FactoryComponent {
associatedtype Argument
associatedtype Service
static var factory: (Resolver) -> (Argument) -> Service { get }
}
public extension FactoryComponent {
public typealias Factory = (Argument) -> Service
}
そして、ここでそれを使用して:
public extension Container {
@discardableResult
public func register<Component: FactoryComponent>(
factory componentType: Component.Type
) -> ServiceEntry<Component.Factory> { // On this line the error shows
return self.register(componentType.Factory.self) { resolver in
componentType.factory(resolver)
}
}
}
エラー:
'コンポーネント' のメンバーの種類を持っていません「工場」と名付けられた。あなたは「ファクトリー」を意味しましたか?
とエラーが無用であるので、当然のことながら、自動修正は役立ちません...
私はスウィフト4破壊の変更をチェックアウトし、汎用的なプロトコルを含む何も表示されませんでした。
これは何を意味するのか理解してもらえますか?
*自己完結型*の例が参考になります。 –