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:
@@ -57,14 +57,14 @@ extension NewTaskView {
|
||||
|
||||
// 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 `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.
|
||||
func save(to modelContext: ModelContext) {
|
||||
/// - Parameter repository: The repository to insert a new todo task.
|
||||
func save(to repository: TodoRepository) {
|
||||
let trimmedTitle = title.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let trimmedNote = note.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
@@ -74,7 +74,7 @@ extension NewTaskView {
|
||||
due: due
|
||||
)
|
||||
|
||||
modelContext.insert(todo)
|
||||
repository.insert(todo)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user