面向Swift协议的编程导致Xcode循环“修复它”

时间:2017-09-26 20:21:55

标签: swift swift-protocols

我有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。 当我点击修复它时,它只会弹出类型别名

0 个答案:

没有答案