0

I have some issues with protocol conformance in Swift. I thought that a protocol inheriting from another protocol automatically conforms to its base protocol. But apparently that's not the case. I expected the following code to work, but it gives me the error message: possibly intended match 'SomeClass.SomeType' (aka 'AnotherProtocol') does not conform to 'SomeProtocol’

protocol SomeProtocol {}
protocol AnotherProtocol: SomeProtocol {}

protocol RequiredProtocol {
    associatedtype SomeType: SomeProtocol
}

class SomeClass: RequiredProtocol {
    typealias SomeType = AnotherProtocol
}

So, what's the use of protocol inheritance when the conformance is not inherited? And what would be the workaround in this case?

  • This is not an obvious duplicate, but Hamish is right; pointing this question to that question is the best path for future searches. The key point is that your typealias in `SomeClass` needs to refer to a concrete type (i.e. a class, struct, or enum), not another protocol. If it's just a protocol, then you've just constrained the type further; you still haven't said what type it *is*. – Rob Napier Nov 27 '16 at 15:19
  • yes, that seems to be the answer. the official swift documentation should be more clear about this. – HenryLadung Nov 27 '16 at 15:57

0 Answers0