I am trying to create a simple list of Views for the user to visit, I cannot figure out how to replace view name with an array variable. In the example below destination: is hard coded as AVExample(), which is one of my views, but how do I use the names in the array?
struct test: View {
var views = ["AVExample", "ColorPickerExample", "DatePickerExample"]
var body: some View {
NavigationView {
List (views, id: \.self){ view in
NavigationLink(
destination: AVExample(),
label: {
Text("\(view)")
})
}
}
}
}
You can create a struct for the views and then use that array of structure. For Example:
And then in your view class(test), create an array of ViewList structure:
Then you can loop over this array as below :