21 Jan 2021 . Min ReadUsing SwiftUI Environments Values to change Tabs programmatically.
In this post, we will explore the Environment Key and EnvironmentValues to achieve the programmatic tab switching in TabView.
Lets start with the empty SwiftUI template from the Xcode and Create new SwiftUI view named AppTabView.swift.
Define AppTabView
Here we define our tabs in AppTabView like below.
struct AppTabView: View {
enum Tab {
case profile
case bookmarks
case settings
}
@State private var selectedTab: Tab = .profile
var body: som