0

Using these protocol definitions:

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 {}

And classes implementing them:

class MyInteractor: MyInteractorLike {
    var active = false
}

class MyPresenter: PresenterLike, Activable {
    let interactor: MyInteractorLike

    init(interactor: MyInteractorLike) {
        self.interactor = interactor
    }
}

I would get an error:

MyPresenter does not conform to protocol Activable

However, when I redefine dependency as a concrete class instead of protocol:

class MyPresenter: PresenterLike, Activable {
    let interactor: MyInteractor

    init(interactor: MyInteractor) {
        self.interactor = interactor
    }
}

Everything is peachy. It looks like there is a problem with matching protocol extension if protocol's associated type is resolved to yet another protocol and not a concrete type.

So I was wondering: am I missing something? Is this a known issue? Do you know of any workarounds?

Jakub Vano
  • 3,833
  • 15
  • 29
  • 1
    This may be another consequence of http://stackoverflow.com/questions/33112559/protocol-doesnt-conform-to-itself: A protocol does not conform to a protocol that it inherits from. – Martin R Dec 09 '15 at 20:59
  • Yes, this looks like the same core problem – Jakub Vano Dec 09 '15 at 21:17

0 Answers0