Files
FamilyMealPlanner/MealMood/MealMoodApp.swift
T
alexandrev-tibco 7da7995538 Fix SwiftData migration crash on schema upgrades
Add = false/true defaults to all non-optional Bool properties so
SwiftData's lightweight migration knows what value to assign existing
rows. Replace try! ModelContainer with crash-safe do-catch that resets
the store on migration failure instead of crashing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-30 11:24:56 +02:00

50 lines
1.4 KiB
Swift

import SwiftUI
import SwiftData
import FirebaseCore
import FirebaseCrashlytics
#if canImport(GoogleMobileAds)
import GoogleMobileAds
#endif
@main
struct MealMoodApp: App {
private let modelContainer: ModelContainer = {
let schema = Schema([
AppSettings.self,
Tag.self,
Dish.self,
WeekPlan.self,
MealSlot.self
])
let configuration = ModelConfiguration(cloudKitDatabase: .none)
do {
return try ModelContainer(for: schema, configurations: [configuration])
} catch {
// Migration failed reset the store to avoid a crash loop
let storeURL = configuration.url
for ext in ["", "-shm", "-wal"] {
try? FileManager.default.removeItem(at: URL(fileURLWithPath: storeURL.path + ext))
}
do {
return try ModelContainer(for: schema, configurations: [configuration])
} catch {
fatalError("Cannot create ModelContainer after reset: \(error)")
}
}
}()
init() {
FirebaseApp.configure()
#if canImport(GoogleMobileAds)
GADMobileAds.sharedInstance().start(completionHandler: nil)
#endif
}
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(modelContainer)
}
}