使用这些协议定义:
protocol Presenter: AnyObject {
typealias InteractorType
var interactor: InteractorType { get }
}
protocol Activable: AnyObject {
var active: Bool { get set }
}
extension Activable where Self: Presenter, Self.InteractorType: Activable {
var active: Bool {
get { return interactor.active }
set { interactor.active = newValue }
}
}
protocol MyInteractorLike: Activable {}
实施它们的类:
class MyInteractor: MyInteractorLike {
var active = false
}
class MyPresenter: PresenterLike, Activable {
let interactor: MyInteractorLike
init(interactor: MyInteractorLike) {
self.interactor = interactor
}
}
我会收到错误:
MyPresenter不符合协议Activable
但是,当我将依赖关系重新定义为具体类而不是协议时:
class MyPresenter: PresenterLike, Activable {
let interactor: MyInteractor
init(interactor: MyInteractor) {
self.interactor = interactor
}
}
一切都很好。如果协议的关联类型被解析为另一个协议而不是具体类型,则看起来匹配协议扩展存在问题。
所以我想知道:我错过了什么吗?这是一个已知的问题?你知道任何解决方法吗?