Task deletion feature (#7)
This PR contains the work done to add support for todo tasks deletion on the *Task list* view. Reviewed-on: rock-n-code/todos-app#7 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #7.
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user