onmyway133 / blog

🍁 What you don't know is what you haven't learned
https://onmyway133.com/
MIT License
677 stars 33 forks source link

How to use TabView with enum in SwiftUI #599

Open onmyway133 opened 4 years ago

onmyway133 commented 4 years ago

Specify tag

enum Authentication: Int, Codable {
    case key
    case certificate
}

TabView(selection: $authentication) {
    KeyAuthenticationView()
        .tabItem {
            Text("🔑 Key")
        }
        .tag(Authentication.key)
    CertificateAuthenticationView()
        .tabItem {
            Text("📰 Certificate")
        }
        .tag(Authentication.certificate)
}
w-i-n-s commented 3 years ago

@onmyway133 only enum Authentication: Int is required (can be enum Authentication: Hashable alternatively).