Post

Replies

Boosts

Views

Activity

Reply to How to convert NavigationLink tag and selection to value?
@EnvironmentObject var workoutManager: WorkoutManager @State var presentedWorkout: [HKWorkoutActivityType] = [] var workoutTypes: [HKWorkoutActivityType] = [.cycling, .running, .walking] var body: some View {         NavigationStack(path: $presentedWorkout) {             List(workoutTypes) { workoutType in                 NavigationLink(                     workoutType.name,                     value: workoutType                 )                 .padding(EdgeInsets(top: 15, leading: 5, bottom: 15, trailing: 5))                 .navigationDestination(for: HKWorkoutActivityType.self) { workoutType in                     SessionPagingView()                 }                 .onChange(of: presentedWorkout) { _ in                     guard let workout = presentedWorkout.last else { return }                     workoutManager.selectedWorkout = workout                 }             }             .listStyle(.elliptical)             .navigationBarTitle("Workouts")             .onAppear {                 workoutManager.requestAuthorization()             }         }     } https://developer.apple.com/documentation/swiftui/navigationstack When click the list, the stack puts the HKWorkoutActivityType data in the presentedWorkout array. So you can use onChange(of) to catch the workout your selected, and set this value to Workoutmanager.selecteWorkout.
Sep ’22