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>
This commit is contained in:
alexandrev-tibco
2026-04-30 11:24:56 +02:00
parent 4ac81d6223
commit 7da7995538
5 changed files with 24 additions and 11 deletions
+4 -4
View File
@@ -4,11 +4,11 @@ import SwiftData
@Model
final class AppSettings {
var mealWindows: String // "dinnerOnly", "lunchOnly", "both"
var includeWeekends: Bool
var includeWeekends: Bool = true
var language: String // "spanish", "english"
var calendarId: String?
var syncEnabled: Bool
var syncEnabled: Bool = false
var syncMode: String? // "weekComplete", "manual"
var lunchTime: Date
var dinnerTime: Date
@@ -18,8 +18,8 @@ final class AppSettings {
var iCloudSyncEnabled: Bool?
var weekExportStyle: String?
var isPremium: Bool
var onboardingCompleted: Bool
var isPremium: Bool = false
var onboardingCompleted: Bool = false
init() {
self.mealWindows = "dinnerOnly"