Basic application setup #1

Merged
javier merged 6 commits from app/setup into main 2026-02-08 20:20:12 +00:00
5 changed files with 19 additions and 14 deletions
Showing only changes of commit f587893ba6 - Show all commits
+4 -3
View File
@@ -1,17 +1,18 @@
import SwiftUI
import SwiftData import SwiftData
import SwiftUI
@main @main
struct TodosApp: App { struct TodosApp: App {
var sharedModelContainer: ModelContainer = { var sharedModelContainer: ModelContainer = {
let schema = Schema([ let schema = Schema([
Item.self, Item.self
]) ])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false) let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
do { do {
return try ModelContainer(for: schema, configurations: [modelConfiguration]) return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch { }
catch {
fatalError("Could not create ModelContainer: \(error)") fatalError("Could not create ModelContainer: \(error)")
} }
}() }()
+11 -7
View File
@@ -1,9 +1,13 @@
import SwiftUI
import SwiftData import SwiftData
import SwiftUI
struct ContentView: View { struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var items: [Item] @Environment(\.modelContext)
private var modelContext
@Query
private var items: [Item]
var body: some View { var body: some View {
NavigationSplitView { NavigationSplitView {
@@ -17,15 +21,15 @@ struct ContentView: View {
} }
.onDelete(perform: deleteItems) .onDelete(perform: deleteItems)
} }
#if os(macOS) #if os(macOS)
.navigationSplitViewColumnWidth(min: 180, ideal: 200) .navigationSplitViewColumnWidth(min: 180, ideal: 200)
#endif #endif
.toolbar { .toolbar {
#if os(iOS) #if os(iOS)
ToolbarItem(placement: .navigationBarTrailing) { ToolbarItem(placement: .navigationBarTrailing) {
EditButton() EditButton()
} }
#endif #endif
ToolbarItem { ToolbarItem {
Button(action: addItem) { Button(action: addItem) {
Label("Add Item", systemImage: "plus") Label("Add Item", systemImage: "plus")
+1 -1
View File
@@ -23,5 +23,5 @@ final class TodosUITestsLaunchTests: XCTestCase {
attachment.lifetime = .keepAlways attachment.lifetime = .keepAlways
add(attachment) add(attachment)
} }
}
}
+2 -2
View File
@@ -2,8 +2,8 @@ import Testing
struct TodosTests { struct TodosTests {
@Test func example() async throws { @Test
func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions. // Write your test here and use APIs like `#expect(...)` to check expected conditions.
} }
} }