Implemented the "deleteTasks(_: at: from: )" function for the LastListViewModel view model in the app target.

This commit is contained in:
2026-02-11 17:33:22 +01:00
parent ac0e0f6556
commit 8324a64b24
2 changed files with 60 additions and 0 deletions
@@ -1,3 +1,4 @@
import Foundation
import SwiftData
import SwiftUI
@@ -84,6 +85,26 @@ extension TaskListView {
// MARK: Methods
/// Deletes tasks at the specified indices.
///
/// This method removes tasks from the model context after a swipe-to-delete action.
/// The deletion is performed through SwiftData's model context, which handles
/// persistence and triggers automatic UI updates.
///
/// - Parameters:
/// - tasks: The current array of tasks.
/// - offsets: The index set of tasks to delete.
/// - modelContext: The SwiftData model context to perform the deletion.
func deleteTasks(
_ tasks: [Todo],
at offsets: IndexSet,
from modelContext: ModelContext
) {
for index in offsets {
modelContext.delete(tasks[index])
}
}
/// Reorders tasks after a drag and drop operation.
///
/// This method is called when users drag and drop tasks to reorder them within a group.