diff --git a/App/Sources/App/TodosApp.swift b/App/Sources/App/TodosApp.swift index ebd7187..e467f70 100644 --- a/App/Sources/App/TodosApp.swift +++ b/App/Sources/App/TodosApp.swift @@ -5,7 +5,7 @@ import SwiftUI struct TodosApp: App { var sharedModelContainer: ModelContainer = { let schema = Schema([ - Item.self + Todo.self ]) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) diff --git a/App/Sources/Models/Item.swift b/App/Sources/Models/Item.swift deleted file mode 100644 index a2f85bf..0000000 --- a/App/Sources/Models/Item.swift +++ /dev/null @@ -1,11 +0,0 @@ -import Foundation -import SwiftData - -@Model -final class Item { - var timestamp: Date - - init(timestamp: Date) { - self.timestamp = timestamp - } -} diff --git a/App/Sources/Models/Todo.swift b/App/Sources/Models/Todo.swift new file mode 100644 index 0000000..b127928 --- /dev/null +++ b/App/Sources/Models/Todo.swift @@ -0,0 +1,42 @@ +import Foundation +import SwiftData + +/// Represents a todo task created by a user. +@Model +final class Todo { + + // MARK: Properties + + /// A date when the todo was completed, if applicable. + var completed: Date? + + /// A date by which the todo should be completed. + var due: Date + + /// An optional note providing additional details about the todo task. + var note: String? + + /// The title of the todo task. + var title: String + + // MARK: Initializers + + /// Creates a new todo item. + /// - Parameters: + /// - title: The title of the todo item. + /// - note: An optional note providing additional details. + /// - due: The date by which the todo should be completed. + /// - completed: The date when the todo was completed, if applicable. + init( + title: String, + note: String? = nil, + due: Date, + completed: Date? = nil + ) { + self.completed = completed + self.due = due + self.note = note + self.title = title + } + +} diff --git a/App/Sources/Views/ContentView.swift b/App/Sources/Views/ContentView.swift index e28a317..96ad30f 100644 --- a/App/Sources/Views/ContentView.swift +++ b/App/Sources/Views/ContentView.swift @@ -7,7 +7,7 @@ struct ContentView: View { private var modelContext @Query - private var items: [Item] + private var items: [Todo] var body: some View { NavigationSplitView { @@ -43,7 +43,7 @@ struct ContentView: View { private func addItem() { withAnimation { - let newItem = Item(timestamp: Date()) + let newItem = Todo(title: "New Todo", due: Date()) modelContext.insert(newItem) } } @@ -59,5 +59,5 @@ struct ContentView: View { #Preview { ContentView() - .modelContainer(for: Item.self, inMemory: true) + .modelContainer(for: Todo.self, inMemory: true) }