Hi guys I'm facing some troubles dealing with stores and arrays with multiple type of items.
Searching through the repo examples I found that with store.IfLet you can deal with optional stores, like in the TicTacToe example. But how can I deal with an array of different items conforming the same protocol?
Some code
struct AppState {
var items: [RowInterface]
}
struct Item1: RowInterface {}
struct Item2: RowInterface {}
ForEachStore(
self.store.scope(state:\.items ,
action: { in _ fatalError() }),
// I want to be able to init one view for Item1 and another for Item2.
content: RowView.init(store:)
)
It's not very elegant, but could you have a generic RowView which takes a RowInterface, then in the body of that view, do something like:
if let item1 = rowInterface as? Item1 { // show Item1View }
if let item2 = rowInterface as? Item2 { // show Item2View }
Yes, I tried. But another issue that I'm facing is conform the generic protocol array to Identifiable.
The ForEachStore rise the "only struct/enum/class types can conform..." error. Any clues?