I have an enum with associated values, which I want to use as an item in RxDataSources. I tried conforming it to identifiable by conforming it to Hashable like below
enum DriverHubWidget: Hashable, Identifiable {
static func == (lhs: DriverHubWidget, rhs: DriverHubWidget) -> Bool {
return lhs.hashValue == rhs.hashValue
}
var id: Int { hashValue }
case greetings(DriverHubGreetingsViewModel)
case scorecard(DriverHubScorecardSummary?, Error?)
case optOut
func hash(into hasher: inout Hasher) {
switch self {
case .greetings( _):
return hasher.combine(1)
case .scorecard( _, _):
return hasher.combine(2)
case .optOut:
return hasher.combine(3)
}
}
}
I implemented the hasher function by simply assigning each case an Int value. Then to conform to identifiable, I added an id property that returns the hashValue. This compiles just fine.
Now when I try to use this to declare a type alias for the section model, like below
typealias WidgetSection = AnimatableSectionModel<String, DriverHubWidget>
It does compile and throws the error, Type 'DriverHubWidget' does not conform to protocol 'IdentifiableType'
I can't understand why it doesn't work, it compiles fine when the enumis comformed to Hashable and Identifiable, but when used the conformance somehow is invalid Is it because the associated values for the enums re not Hashable?