View Initializes Twice

Hello All,

The main view of my app is embedded inside a Navigation View, which is embedded inside a TabView. This results in the main view being initialized twice and api calls are being made twice as well. Any way to reduce the amount of times the view is initialized or api calls being made would be greatly appreciated!

Any way to reduce the amount of times the view is initialized or api calls being made would be greatly appreciated!

In SwiftUI, initializers of Views may be called unpredictable times. You should better not make API calls in the initializers of Views.
Better try onAppear.
The api calls are still being made twice even inside the onAppear function

The api calls are still being made twice even inside the onAppear function

Can you show your code?
I will try a couple other things, thanks!
Thanks for showing your code. But it lacks many parts and misspelled identifiers so I cannot try it.
View Initializes Twice
 
 
Q