Initial Commit

This commit is contained in:
2026-09-04 12:43:10 -03:00
commit 4d36df488f
12 changed files with 959 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
//
// ContentView.swift
// Bible-Week
//
// Created by Matheus A Silveira on 04/09/26.
//
import SwiftUI
import SwiftData
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var items: [Item]
var body: some View {
NavigationViewWrapper {
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)
}
#if os(macOS)
.navigationSplitViewColumnWidth(min: 180, ideal: 200)
#endif
.toolbar {
#if os(iOS)
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
#endif
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
}
}
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])
}
}
}
}
fileprivate struct NavigationViewWrapper<Content: View>: View {
let content: () -> Content
var body: some View {
#if os(macOS)
NavigationSplitView {
content()
} detail: {
Text("Select an item")
}
#else
content()
#endif
}
}
#Preview {
ContentView()
.modelContainer(for: Item.self, inMemory: true)
}