I am using ReactiveSwift
. There are two protocols: CommonProtocol
and SpecificProtocol
.
When I use SpecificProtocol
in map
function there is an error Type 'any SpecificProtocol' cannot conform to 'Equatable'. However it is perfectly fine with using ConreateItem
protocol CommonProtocol {}
protocol SpecificProtocol: CommonProtocol, Equatable
extension SpecificProtocol where Self: Equatable {
static func == (lhs: Self, rhs: Self) -> Bool { return true }
}
class ConreateItem: SpecificProtocol{}
var messages = MutableProperty<[CommonProtocol]?>(nil)
messages.producer
// .map({ $0 as? [ConreateItem] }) //that is ok
.map({ $0 as? [any SpecificProtocol] })//Type 'any SpecificProtocol' cannot conform to'Equatable'
.skipRepeats()
I don't understand why/how SpecificProtocol
is converted to any SpecificProtocol
. And what is the correct way to implement Equatable
constraint on protocol so I could use it in map
function (Equatable
is required for high order function in my case)
map
is of ReactiveSwift