I understood that you would a single click on the "+" button create a new List's item and follows its link.
If it is so the NavigationLink init has to be the one with a tag and reference to a tags' selection, the addJob function have to create the new job's item and set the reference to point to it.
The simplified code below use an, improper, set of Int as job's ID.
import SwiftUI
struct ContentView: View {
var body: some View {
JobsView()
}
}
extension Int: Identifiable
{
public var id: Self { self }
}
struct JobsView: View {
@State private var jobs = [0, 1, 2]
@State private var selection: Int? = nil
var body: some View {
NavigationView {
List {
ForEach(jobs) { job in
NavigationLink("job \(job)",
destination: JobOverView(job: job),
tag: job,
selection: $selection)
}
}
.toolbar {
Button(action: addJob,
label: {Image(systemName:"plus")}
)
}
.navigationTitle("Jobs")
}
}
private func addJob() {
jobs.append(jobs.last!+1)
selection = jobs.last
}
}
struct JobOverView: View {
let job: Int
var body: some View {
Label("Job Info \(job)", systemImage: "chevron.down.circle.fill")
}
}