5 // Created by Ruben Beltran del Rio on 7/24/23.
11 struct ContentView: View {
12 @Environment(\.modelContext) private var modelContext
13 @Query private var items: [Item]
18 ForEach(items) { item in
20 Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
22 Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
25 .onDelete(perform: deleteItems)
29 Button(action: addItem) {
30 Label("Add Item", systemImage: "plus")
34 Text("Select an item")
38 private func addItem() {
40 let newItem = Item(timestamp: Date())
41 modelContext.insert(newItem)
45 private func deleteItems(offsets: IndexSet) {
47 for index in offsets {
48 modelContext.delete(items[index])
56 .modelContainer(for: Item.self, inMemory: true)