-
Hi! I'm experimenting with TCA and I'd like to create a page tab view. My code is:
So this way when I start the app it prints:
and if I swipe to change tab, on every tab change all of the However, if I change the
it prints the same thing ONCE and no more on tab changes. Am I missing something? Or is this a bug? Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @csbence10, thanks for the discussion and I was able to reproduce this too. It's very strange. There must be some kind of special SwiftUI magic when using FWIW, you should't fret too much about the |
Beta Was this translation helpful? Give feedback.
Hey @csbence10, thanks for the discussion and I was able to reproduce this too. It's very strange. There must be some kind of special SwiftUI magic when using
@State
bindings inTabView
that prevents the additionalinit
s. If you convert the@State
to@ObservedObject
you will see that theinit
s are called gain. So definitely seems like a SwiftUI bug 😬.FWIW, you should't fret too much about the
.init
calls. Since you should never do series work in the initializer of a view those calls are usually not a problem. It's the calls to thebody
that can be expensive (with sufficiently complex view hierarchies), and theWithViewStore
is preventing those from being invoked too many times.