我有2个通用摘要:
protocol NavigationDelegate: class { }
和
protocol ViewModelDelegate: class { }
然后我有一个更详细的ViewModel协议:
protocol ViewModel: class {
associatedtype ViewModelDelegateConformance: ViewModelDelegate
associatedtype NavigationDelegateConformance: NavigationDelegate
init(delegate: ViewModelDelegateConformance, navigationDelegate: NavigationDelegateConformance)
}
然后我有2个协议,每个协议分别符合前两个协议
protocol AnyNavigationDelegate: NavigationDelegate {
func anySelected(for post: Any)
}
和
protocol AnyViewModelDelegate: ViewModelDelegate {
func someViewModelAnyUpdated(viewModel: SomeViewModel)
func someViewModelFailedUpdate(viewModel: SomeViewModel)
}
然后我有了我的ViewModel类
class SomeViewModel: ViewModel {
typealias ViewModelDelegateConformance = AnyViewModelDelegate
typealias NavigationDelegateConformance = AnyNavigationDelegate
required init(delegate: ViewModelDelegateConformance, navigationDelegate: NavigationDelegateConformance) {
}
}
但我一直收到错误:SomeViewModel不符合ViewModel。 当我点击修复它时,它只会弹出类型别名