43 lines
1.3 KiB
Swift
43 lines
1.3 KiB
Swift
import SwiftUI
|
|
import SwiftData
|
|
|
|
@main
|
|
struct BusinessCardWatchApp: App {
|
|
private let modelContainer: ModelContainer
|
|
@State private var cardStore: WatchCardStore
|
|
|
|
init() {
|
|
let schema = Schema([WatchCard.self])
|
|
|
|
let appGroupURL = FileManager.default.containerURL(
|
|
forSecurityApplicationGroupIdentifier: "group.com.mbrucedogs.BusinessCard"
|
|
)
|
|
|
|
let storeURL = appGroupURL?.appending(path: "BusinessCard.store")
|
|
?? URL.applicationSupportDirectory.appending(path: "BusinessCard.store")
|
|
|
|
let configuration = ModelConfiguration(
|
|
schema: schema,
|
|
url: storeURL,
|
|
cloudKitDatabase: .automatic
|
|
)
|
|
|
|
do {
|
|
let container = try ModelContainer(for: schema, configurations: [configuration])
|
|
self.modelContainer = container
|
|
let context = container.mainContext
|
|
self._cardStore = State(initialValue: WatchCardStore(modelContext: context))
|
|
} catch {
|
|
fatalError("Failed to create ModelContainer: \(error)")
|
|
}
|
|
}
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
WatchContentView()
|
|
.environment(cardStore)
|
|
}
|
|
.modelContainer(modelContainer)
|
|
}
|
|
}
|