I'm developing a screen in SwiftUI and have the following code:
...
@EnvironmentObject var externalState: MainStateObject
...
SelectOptionPopover(options: $externalState.depots,
selectedOption: selectedDepot,
prompt: "Depot: ")
...
SelectOptionPopover is a view that I created to handle a variety of popovers. For the options, it expects an array of [SelectOptionPopoverOption], which is declared like this:
protocol SelectOptionPopoverOption {
var displayName: String { get }
}
Now, the issue I have is that when I pass an array of SelectOptionPopoverOptions, it works just fine. But if I pass an array of another type that conforms to SelectOptionPopoverOptions, the conversion fails with something like:
'Binding<[Depot]>' is not convertible to 'Binding<[SelectOptionPopoverOption]>'
These may be the exact same objects, but work when they're identified as SelectOptionPopoverOptions but not when identified as a Depots.
I can work around this by using arrays of SelectedOptionPopoverOption and casting them as needed, but it would sure be cleaner to be able to use the conforming types instead.
Any ideas on how I could use the more specific types instead?