Skip to content

Child view init called everytime tab changes #391

Answered by mbrandonw
csbence10 asked this question in Q&A
Discussion options

You must be logged in to vote

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 in TabView that prevents the additional inits. If you convert the @State to @ObservedObject you will see that the inits 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 the body that can be expensive (with sufficiently complex view hierarchies), and the WithViewStore is preventing those from being invoked too many times.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by csbence10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants