Todo repository protocol #8
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user