Post

Replies

Boosts

Views

Activity

Comment on ForEach - Deleting last index causes Index out of bounds error
Here is my code: @Binding var workouts: [Workout] @State private var showWorkoutStudioEditor = false @State private var sortedBy: SortBy = .nameAscending      @Environment(.scenePhase) private var scenePhase let saveAction: () -> Void var body: some View {         NavigationView {             ScrollView(showsIndicators: true) {                 ForEach($workouts, id: .id) { workout in                     if !(sortedBy == .favorites) || workout.isFavorite.wrappedValue {                         WorkoutCard(                             workout: workout,                             workouts: $workouts,                             removeWorkout: removeWorkout                         )                             .padding([.leading, .trailing])                     }                 } } }                                  Spacer()             }
Oct ’21