I have an API endpoint that returns array of various items, so I have created an enum
that can hold those items and therefore I can create an array of them - more less like below
let arr: [CollectableEnum] = [
.feed(.init(id: "1")),
.clinic(.init(id: "1")),
.feed(.init(id: "2")),
]
Now I need to iterate through them and display properly in SwiftUI
I wonder, how to get an value from that enum, so I can get an ItemModel
rather than CollectableEnum
that holds that ItemModel
enum code:
enum CollectableEnum: Identifiable, Hashable {
case feed(ItemModel)
case clinic(ClinicModel)
var id: String {
switch self {
case .feed(let feed):
return feed.id
case .clinic(let clinic):
return clinic.id
}
}
// what return type should I put here?
var associatedValue {
switch self {
case .feed(let feed):
return feed
case .clinic(let clinic):
return clinic
}
}
public func hash(into hasher: inout Hasher) {
return hasher.combine(self)
}
}