Hi,
Is there a way of specifying a destination for a NavigationLink that is passed as init parameter?
I have this code:
And my intention is to have, instead of the ternary operator in the destination parameter, directly the view that I passed as parameter at init.
For example, call the view like this:
And the view remains like this:
With this approach, I can have multiple items in a list with different destination but with the same codebase.
Thank you so much.
F.
Is there a way of specifying a destination for a NavigationLink that is passed as init parameter?
I have this code:
Code Block Swift struct RowLine: View { var text: String var imageName: String var body: some View { NavigationLink(destination: text == "Settings" ? SettingsView() : MyInfoView()){ HStack{ Image(systemName: imageName) Text(text) } } } }
And my intention is to have, instead of the ternary operator in the destination parameter, directly the view that I passed as parameter at init.
For example, call the view like this:
Code Block Swift RowLine(text: "Settings", imageName: "gearshape", nextView: myNextView())
And the view remains like this:
Code Block Swift struct RowLine: View { var text: String var imageName: String var nextView: View /*Of course, this is ilegal*/ var body: some View { NavigationLink(destination: nextView){ HStack{ Image(systemName: imageName) Text(text) } } } }
With this approach, I can have multiple items in a list with different destination but with the same codebase.
Thank you so much.
F.