Updated the "save(to: )" function of the NewTaskViewModel view model in the app target to use the Repository protocol instead.

This commit is contained in:
2026-02-11 17:47:40 +01:00
parent fb8815dafc
commit 85bd3f6a38
@@ -57,14 +57,14 @@ extension NewTaskView {
// MARK: Functions // MARK: Functions
/// Saves a new todo task to the SwiftData model context. /// Saves a new todo task to the repository.
/// ///
/// This function creates a new `Todo` instance with the current property values and inserts it into the provided model context. /// This function creates a new `Todo` instance with the current property values and inserts it into the provided repository.
/// The title and note are trimmed of leading and trailing whitespace before saving. /// The title and note are trimmed of leading and trailing whitespace before saving.
/// The `note` property value is only included if it's not empty after trimming. /// The `note` property value is only included if it's not empty after trimming.
/// ///
/// - Parameter modelContext: The SwiftData model context to insert a new todo task. /// - Parameter repository: The repository to insert a new todo task.
func save(to modelContext: ModelContext) { func save(to repository: Repository) {
let trimmedTitle = title.trimmingCharacters(in: .whitespacesAndNewlines) let trimmedTitle = title.trimmingCharacters(in: .whitespacesAndNewlines)
let trimmedNote = note.trimmingCharacters(in: .whitespacesAndNewlines) let trimmedNote = note.trimmingCharacters(in: .whitespacesAndNewlines)
@@ -74,7 +74,7 @@ extension NewTaskView {
due: due due: due
) )
modelContext.insert(todo) repository.insert(todo)
} }
} }