4 struct PreferencesWindow: View {
5 @Environment(\.modelContext) private var modelContext
6 @Query private var items: [Item]
11 ForEach(items) { item in
13 Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
15 Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
18 .onDelete(perform: deleteItems)
22 Button(action: addItem) {
23 Label("Add Item", systemImage: "plus")
27 Text("Select an item")
31 private func addItem() {
33 let newItem = Item(timestamp: Date())
34 modelContext.insert(newItem)
38 private func deleteItems(offsets: IndexSet) {
40 for index in offsets {
41 modelContext.delete(items[index])
49 .modelContainer(for: Item.self, inMemory: true)