I am trying to convert a design of mine to be pop
. However I am stuck and already have bunch of threads for my approaches -not a duplicate of this question though- and apparently they are all dead end.
My question is, is there a way to override parameter types of a protocol method which inherited from another protocol?
struct Books: Codable {}
protocol Listener {
func listen(_ param: Codable)
}
protocol BooksListener: Listener {
func listen(_ param: Books)
}
class MyClass: BooksListener {
// I want only this one to required with the type.
func listen(_ param: Books) {
<#code#>
}
func listen(_ param: Codable) {
<#code#>
}
}
I did my research and I believe this is not how protocols work. I am just seeking a solution to this.
I tried to add a associatedType
to the Listener
and use it as the type inside listen(_:)
. But this solution restricts any class to have conformance to multiple protocols which inherits from Listener
. Details can be found here