2.0: fix crash de arranque por IDs duplicados (CloudKit)

Fatal error "Duplicate values for key" al construir diccionarios con
Dictionary(uniqueKeysWithValues:) sobre dishes/tags/slots cuyos UUID se
duplican por la sincronización CloudKit de 2.0. Se sustituyen todas las
ocurrencias por Dictionary(_, uniquingKeysWith:) para tolerar duplicados
(se conserva el primero) en lugar de abortar. La app ya no crashea al
abrir con datos duplicados; la deduplicación real queda pendiente aparte.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A3HaWmmtTQ1vdTERtSYU6p
This commit is contained in:
alexandrev-tibco
2026-07-22 18:23:50 +02:00
parent 817ae549dc
commit 5272f6533f
5 changed files with 15 additions and 15 deletions
+3 -3
View File
@@ -352,9 +352,9 @@ final class HomeViewModel: ObservableObject {
private func captureUndoSnapshot(plan: WeekPlan) {
guard !isApplyingUndo else { return }
lastWeekStartSnapshot = plan.weekStartDate
lastSlotsSnapshot = Dictionary(uniqueKeysWithValues: plan.slotList.map { slot in
lastSlotsSnapshot = Dictionary(plan.slotList.map { slot in
(slot.id, SlotSnapshot(dishId: slot.dishId, isRuleOverridden: slot.isRuleOverridden, isEatingOut: slot.isEatingOut))
})
}, uniquingKeysWith: { first, _ in first })
hasUndoSnapshot = true
}
@@ -410,7 +410,7 @@ final class HomeViewModel: ObservableObject {
}
private func syncAllAssignedSlotsToCalendar(plan: WeekPlan, dishes: [Dish], settings: AppSettings) {
let dishById = Dictionary(uniqueKeysWithValues: dishes.map { ($0.id, $0) })
let dishById = Dictionary(dishes.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
for slot in plan.slotList {
guard let dishId = slot.dishId, let dish = dishById[dishId] else {
if let eventId = slot.calendarEventId {