summaryrefslogtreecommitdiffstats
path: root/Solverv/ContentView.swift
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-12-15 23:42:01 +0100
committerivar <i@oiee.no>2025-12-15 23:42:01 +0100
commit0e1635b057903434c0f193ad9ead7035150b0773 (patch)
tree5838be9d71966099aa2b13d96c5b3a5215a534b0 /Solverv/ContentView.swift
downloadsolverv-0e1635b057903434c0f193ad9ead7035150b0773.tar.xz
solverv-0e1635b057903434c0f193ad9ead7035150b0773.zip
Initial Commit
Diffstat (limited to 'Solverv/ContentView.swift')
-rw-r--r--Solverv/ContentView.swift61
1 files changed, 61 insertions, 0 deletions
diff --git a/Solverv/ContentView.swift b/Solverv/ContentView.swift
new file mode 100644
index 0000000..b82e2c7
--- /dev/null
+++ b/Solverv/ContentView.swift
@@ -0,0 +1,61 @@
+//
+// ContentView.swift
+// Solverv
+//
+// Created by Ivar Løvlie on 15/12/2025.
+//
+
+import SwiftUI
+import SwiftData
+
+struct ContentView: View {
+ @Environment(\.modelContext) private var modelContext
+ @Query private var items: [Item]
+
+ var body: some View {
+ NavigationSplitView {
+ List {
+ ForEach(items) { item in
+ NavigationLink {
+ Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
+ } label: {
+ Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
+ }
+ }
+ .onDelete(perform: deleteItems)
+ }
+ .toolbar {
+ ToolbarItem(placement: .navigationBarTrailing) {
+ EditButton()
+ }
+ ToolbarItem {
+ Button(action: addItem) {
+ Label("Add Item", systemImage: "plus")
+ }
+ }
+ }
+ } detail: {
+ Text("Select an item")
+ }
+ }
+
+ private func addItem() {
+ withAnimation {
+ let newItem = Item(timestamp: Date())
+ modelContext.insert(newItem)
+ }
+ }
+
+ private func deleteItems(offsets: IndexSet) {
+ withAnimation {
+ for index in offsets {
+ modelContext.delete(items[index])
+ }
+ }
+ }
+}
+
+#Preview {
+ ContentView()
+ .modelContainer(for: Item.self, inMemory: true)
+}