From e105af147dad65ee4a14cdcd9f4be91f8a8b6bdb Mon Sep 17 00:00:00 2001 From: kutesir Date: Wed, 27 May 2026 23:55:38 +0300 Subject: [PATCH] fix: migrate persisted gamified emojis on load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UserDefaults retained the old 🔥/💥 emojis from before the sample data was cleaned. On init, replace those emojis in loaded programs and persist the result so they don't reappear after restart. --- KisaniCal/Models/ExerciseModels.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/KisaniCal/Models/ExerciseModels.swift b/KisaniCal/Models/ExerciseModels.swift index f600299..e168cce 100644 --- a/KisaniCal/Models/ExerciseModels.swift +++ b/KisaniCal/Models/ExerciseModels.swift @@ -190,7 +190,13 @@ class WorkoutViewModel: ObservableObject { let saved = try? JSONDecoder().decode([WorkoutProgram].self, from: data), !saved.isEmpty { - programs = saved + let gamifiedEmojis: Set = ["🔥", "💥"] + let emojiMap = ["🔥": "🔄", "💥": "🏋️"] + let needsMigration = saved.contains(where: { gamifiedEmojis.contains($0.emoji) }) + programs = needsMigration ? saved.map { p in + guard let replacement = emojiMap[p.emoji] else { return p } + var copy = p; copy.emoji = replacement; return copy + } : saved var sched: [Int: UUID] = [:] if let dict = UserDefaults.standard.dictionary(forKey: Self.kSchedule) as? [String: String] { @@ -205,7 +211,9 @@ class WorkoutViewModel: ObservableObject { let uid = UUID(uuidString: str), saved.contains(where: { $0.id == uid }) { pid = uid } activeProgramId = pid - activeSections = saved.first { $0.id == pid }?.sections ?? saved[0].sections + activeSections = programs.first { $0.id == pid }?.sections ?? programs[0].sections + + if needsMigration { save() } } else { // ── First launch: seed with sample programs ──