私は彼らの両方がassociatedtypesを持って、2つのプロトコルを宣言する必要があります。この現在のプロトコルの定義では2つのプロトコル間で関連タイプを共有するにはどうすればよいですか?
protocol MyView {
associatedtype DataType
associatedtype LayoutType : MyLayout
var data: DataType { get }
var layout: LayoutType { get }
func doLayout()
}
protocol MyLayout {
associatedtype DataType
func computeLayout(with data: DataType?)
}
、MyView
のassociatedtype DataType
は本当にMyLayout
におけるものと同じではありません。
extension MyView {
func doLayout() {
layout.computeLayout(with: self.data)
^^^^^^^^^
Cannot convert value of type 'Self.DataType' to expected argument type '_?'
}
}
コンパイラは型が同じではないことを私たちに伝えています。
問題を解決するために2つのプロトコル間で関連タイプを共有する方法はありますか?ありがとう。
、おそらくあなたは、他の2 – Alexander
@AlexanderMomchliovから継承プロトコルを作ることを意味 - 私はすでに(https://gist.github.com/anonymous/58fb6e95549081ba8eff9c7fc81d6fc2)それを試してみましたが、それが同じエラーで失敗します。 – MartinMoizard