diff --git a/Workouts/Views/Today/ScheduleAddEditView.swift b/Workouts/Views/Today/ScheduleAddEditView.swift index f5ad674..2be4928 100644 --- a/Workouts/Views/Today/ScheduleAddEditView.swift +++ b/Workouts/Views/Today/ScheduleAddEditView.swift @@ -117,8 +117,14 @@ struct ScheduleAddEditView: View { private var isEditing: Bool { scheduleID != nil } - /// The live routine currently selected; nil when the stored id no longer resolves. - private var selectedRoutine: Routine? { routines.first { $0.id == routineID } } + /// The live routine currently selected, following the seed clone-on-edit redirect + /// (a schedule made against a starter seed keeps the retired seed id after the + /// routine is edited); nil when the routine has been deleted. + private var selectedRoutine: Routine? { + guard !routineID.isEmpty else { return nil } + let liveID = sync.currentRoutineID(for: routineID) + return routines.first { $0.id == liveID } + } /// The When choices this presentation offers — "Now" only when adding on today. /// Built as a list (rather than conditionally hiding a tag inside the Picker) @@ -171,7 +177,8 @@ struct ScheduleAddEditView: View { private var routineSection: some View { Section { NavigationLink { - RoutinePickerList(routines: routines, selectedID: $routineID) + RoutinePickerList(routines: routines, currentID: selectedRoutine?.id, + selectedID: $routineID) } label: { HStack { Text("Routine") @@ -333,6 +340,9 @@ struct ScheduleAddEditView: View { /// Tapping selects and pops back. private struct RoutinePickerList: View { let routines: [Routine] + /// The resolved live id of the current selection (for the checkmark) — may differ + /// from the binding's stored value when a seed clone-on-edit redirect is in play. + let currentID: String? @Binding var selectedID: String @Environment(\.dismiss) private var dismiss @@ -350,7 +360,7 @@ private struct RoutinePickerList: View { Text(routine.name) .foregroundStyle(.primary) Spacer() - if routine.id == selectedID { + if routine.id == currentID { Image(systemName: "checkmark") .fontWeight(.semibold) .foregroundStyle(Color.accentColor)