I have two enums that conform to one protocol, an observable object that holds arrays of those enums and a view that I want to accept both enums.
The observable object:
class OptionsStore: ObservableObject {
@Published var topicOptions: [TopicOption]
@Published var levelOptions: [LevelOption]
}
One of the enums and the protocol:
enum TopicOption: String, CaseIterable, OptionCompatible {
case music, food, traffic
...
}
protocol OptionCompatible {
...
}
The views:
struct MainView: View {
@EnvironmentObject var optionsStore: OptionsStore
var body: some View {
OptionsView(
options: TopicOption.allCases, // no error
activeOptions: self.$optionsStore.topicOptions // error
)
}
}
struct OptionsView: View {
let options: [OptionCompatible]
@Binding var activeOptions: [OptionCompatible]
}
The error is
Cannot convert value of type 'Binding<[TopicOption]>' to expected argument type 'Binding<[OptionCompatible]>'
What I want is the OptionsView to accept both enums. Why does it go well by calling the static allCases, but not when I pass an array of those enums? How do I fix this?