diff options
Diffstat (limited to 'ShedCalc')
| -rw-r--r-- | ShedCalc/Assets.xcassets/AccentColor.colorset/Contents.json | 11 | ||||
| -rw-r--r-- | ShedCalc/Assets.xcassets/AppIcon.appiconset/Contents.json | 58 | ||||
| -rw-r--r-- | ShedCalc/Assets.xcassets/Contents.json | 6 | ||||
| -rw-r--r-- | ShedCalc/ContentView.swift | 59 | ||||
| -rw-r--r-- | ShedCalc/Item.swift | 18 | ||||
| -rw-r--r-- | ShedCalc/ShedCalcApp.swift | 32 |
6 files changed, 184 insertions, 0 deletions
diff --git a/ShedCalc/Assets.xcassets/AccentColor.colorset/Contents.json b/ShedCalc/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/ShedCalc/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ShedCalc/Assets.xcassets/AppIcon.appiconset/Contents.json b/ShedCalc/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..3f00db4 --- /dev/null +++ b/ShedCalc/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ShedCalc/Assets.xcassets/Contents.json b/ShedCalc/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/ShedCalc/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ShedCalc/ContentView.swift b/ShedCalc/ContentView.swift new file mode 100644 index 0000000..c19fdb3 --- /dev/null +++ b/ShedCalc/ContentView.swift @@ -0,0 +1,59 @@ +// +// ContentView.swift +// ShedCalc +// +// Created by Jacky Jack on 28/07/2026. +// + +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) + } + .navigationSplitViewColumnWidth(min: 180, ideal: 200) + .toolbar { + 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) +} diff --git a/ShedCalc/Item.swift b/ShedCalc/Item.swift new file mode 100644 index 0000000..55989b7 --- /dev/null +++ b/ShedCalc/Item.swift @@ -0,0 +1,18 @@ +// +// Item.swift +// ShedCalc +// +// Created by Jacky Jack on 28/07/2026. +// + +import Foundation +import SwiftData + +@Model +final class Item { + var timestamp: Date + + init(timestamp: Date) { + self.timestamp = timestamp + } +} diff --git a/ShedCalc/ShedCalcApp.swift b/ShedCalc/ShedCalcApp.swift new file mode 100644 index 0000000..4a5c6ff --- /dev/null +++ b/ShedCalc/ShedCalcApp.swift @@ -0,0 +1,32 @@ +// +// ShedCalcApp.swift +// ShedCalc +// +// Created by Jacky Jack on 28/07/2026. +// + +import SwiftUI +import SwiftData + +@main +struct ShedCalcApp: App { + var sharedModelContainer: ModelContainer = { + let schema = Schema([ + Item.self, + ]) + let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) + + do { + return try ModelContainer(for: schema, configurations: [modelConfiguration]) + } catch { + fatalError("Could not create ModelContainer: \(error)") + } + }() + + var body: some Scene { + WindowGroup { + ContentView() + } + .modelContainer(sharedModelContainer) + } +} |
