1 min readJul 8, 2019
Unfortunately, at this time the cleanest approach seems to :
struct ContentViewPresentation : View {
var list = ["Michael","Zach","Parshav"]
var body: some View {
NavigationView {
List(list.identified(by: \.self)) { item in
if item.contains("Z") {
PresentationLink(destination: OtherDetailView(item: item)) {
Text(item)
}
} else {
PresentationLink(destination: DetailView(item: item)) {
Text(item)
}
}
}
.navigationBarTitle("NavigationLink")
}
}
}
You can do…
struct ContentViewPresentation2 : View {
var list = ["Michael","Zach","Parshav"]
func navigate(_ item:String) -> some View {
Group {
if item.contains("Z") {
OtherDetailView(item: item)
} else {
DetailView(item: item)
}
}
}
var body: some View {
NavigationView {
List(list.identified(by: \.self)) { item in
PresentationLink(destination: self.navigate(item)) {
Text(item)
}
}
.navigationBarTitle("NavigationLink")
}
}
}
With only one navigation link, but the destination returned by the navigate function has to be wrapped in a group. Opaque typing only goes so far.