mercredi 22 janvier 2020

SwiftUI doesn't like switch?

Trying to following this discussion, I implemented the suggestion of Yurii Kotov:

struct ContentView: View {

@State private var index = 0

@ViewBuilder
 var body: some View {
   if index == 0 {
       MainView()
   } else {
       LoginView()
   }
}

It works fine. But if I try to use a switch statement instead:

    switch  index {
        case 0: MainView()
        case 1: LoginView()
        default:
            print("# error in switch")
        }

nothing happens. There is no mistake alert, but also no result at all. Could somebody help?

Aucun commentaire:

Enregistrer un commentaire