I have a control that sets an @State variable to keep track of the selected tabs in a custom tab View. I can set the @State variable in code by setting the following:
@State var selectedTab: Int = 1
How do I set the initial value programmatically so that I can change the selected tab when the view is created?
I have tried the following:
1:
@State var selectedTab: Int = (parameter == true ? 1 : 2)
2:
init(default: Int) {
self.$selectedTab = default
}