0
  let datasource = [
    "view1",
    "view2",
    "view3",
    "view4",
    "view5",
    "view6",
    ...
  ]

I want to display datasource in a list, and push to different view, such as View1(), View2(), View3(), View4()...

What should I do in SwiftUI?

zzzwco
  • 184
  • 6
  • 1
    Learn SwiftUI, then show your own try and refer this https://stackoverflow.com/help/how-to-ask, and then someone probably could help you. – Asperi May 22 '20 at 07:11

1 Answers1

0

Here is an example on how to programmatically decide to which view you want to go. This could be used in a List as well...

struct ProgrammaticNavigationExampleView: View {

    enum NavDestination {
        case red
        case green
    }

    @State var destination : NavDestination?

    var body: some View {
        VStack(spacing: 20) {
            NavigationLink(destination: Color.red, tag: NavDestination.red, selection: $destination) {
                EmptyView()
            }
            NavigationLink(destination: Color.green, tag: NavDestination.green, selection: $destination) {
                EmptyView()
            }
            Text("Page 1")
            Button("Show random page") {
                self.destination = [.red, .green].randomElement()!
            }
        }
        .navigationBarTitle("Page 1")
    }

}

struct ProgrammaticNavigationExample_Previews: PreviewProvider {
    static var previews: some View {
        NavigationView {
            ProgrammaticNavigationExampleView()
        }
    }
}
Ralf Ebert
  • 3,556
  • 3
  • 29
  • 43