Unsure how to use SwitchStore for an Enum State that is embedded within a conventional Struct State. #753
Replies: 1 comment 1 reply
-
Hi @james-rantmedia, the problem is that you are applying If you don't need this additional layer of nesting you could flatten it to just a single enum and then your code would work as-is. Or, if that's not right for your situation, you need to first SwitchStore(store.scope(state: \.activeFeature)) {
...
} Also, I just wanna mention that sending actions from a view's initializer is not doing to be a good idea in the long run. You should consider view initialization to be a process that can happen many, many times out of your control, and so it doesn't directly map to an actual lifecycle event, such as "appearing". It is usually better to tap into BTW, the compiler error you were seeing has gotten a bit better in the newest Xcode beta:
That's a lot to take in, but at least you can see that in one part it is referring to |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I'm trying to use SwitchStore two conditionally show different views based on an
activeFeature
.My set up is a Main Store (I guess equivalent to the App Store / State in the examples) with two other Features, each with their own states, reducers, actions etc.
The
MainState
has an enum:and a corresponding var:
var activeFeature: FeatureState = .featureOne(FeatureOneState(label: ""))
I've added
.pullback
enhancements to theMainReducer
to expose the stores for the feature wrapped in the enum.The intention is to be able to switch the active feature using this var, and have the
SwitchStore
swap out the view when it happens.I've hit a road block though, where Swift just produces the error:
Obviously something about my setup is incorrect, but I'm at a loss as to what it is.
I've included a self-contained example showing the issue, hopefully looking at the code itself may shed more light on the problem than my vague description above.
SwitchStoreTest.zip
Beta Was this translation helpful? Give feedback.
All reactions