Updated the "delete(_: at: from: )" function of the TaskListViewModel view model in the app target to use the Repository protocol instead.
This commit is contained in:
@@ -87,21 +87,21 @@ extension TaskListView {
|
|||||||
|
|
||||||
/// Deletes tasks at the specified indices.
|
/// Deletes tasks at the specified indices.
|
||||||
///
|
///
|
||||||
/// This method removes tasks from the model context after a swipe-to-delete action.
|
/// This method removes tasks from the repository after a swipe-to-delete action.
|
||||||
/// The deletion is performed through SwiftData's model context, which handles
|
/// The deletion is performed through the repository, which handles
|
||||||
/// persistence and triggers automatic UI updates.
|
/// persistence and triggers automatic UI updates.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - tasks: The current array of tasks.
|
/// - tasks: The current array of tasks.
|
||||||
/// - offsets: The index set of tasks to delete.
|
/// - offsets: The index set of tasks to delete.
|
||||||
/// - modelContext: The SwiftData model context to perform the deletion.
|
/// - repository: The repository to perform the deletion.
|
||||||
func deleteTasks(
|
func delete(
|
||||||
_ tasks: [Todo],
|
_ tasks: [Todo],
|
||||||
at offsets: IndexSet,
|
at offsets: IndexSet,
|
||||||
from modelContext: ModelContext
|
from repository: Repository
|
||||||
) {
|
) {
|
||||||
for index in offsets {
|
for index in offsets {
|
||||||
modelContext.delete(tasks[index])
|
repository.delete(tasks[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ struct TaskListView: View {
|
|||||||
group: viewModel.group,
|
group: viewModel.group,
|
||||||
showCompleted: viewModel.showCompleted
|
showCompleted: viewModel.showCompleted
|
||||||
) { tasks, offsets in
|
) { tasks, offsets in
|
||||||
viewModel.deleteTasks(
|
viewModel.delete(
|
||||||
tasks,
|
tasks,
|
||||||
at: offsets,
|
at: offsets,
|
||||||
from: modelContext
|
from: modelContext
|
||||||
|
|||||||
Reference in New Issue
Block a user