Todo repository protocol (#8)
This PR contains the work done to decouple the direct use of the `ModelContext` from `SwiftData` from the view model that uses it. In addition, the project transitioned to use Swift 6 and strict concurrency which brought some issues with the unit tests, so they were amended as well. Reviewed-on: rock-n-code/todos-app#8 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 #8.
This commit is contained in:
@@ -87,21 +87,21 @@ extension TaskListView {
|
||||
|
||||
/// 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
|
||||
/// This method removes tasks from the repository after a swipe-to-delete action.
|
||||
/// The deletion is performed through the repository, 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(
|
||||
/// - repository: The repository to perform the deletion.
|
||||
func delete(
|
||||
_ tasks: [Todo],
|
||||
at offsets: IndexSet,
|
||||
from modelContext: ModelContext
|
||||
from repository: TodoRepository
|
||||
) {
|
||||
for index in offsets {
|
||||
modelContext.delete(tasks[index])
|
||||
repository.delete(tasks[index])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user