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:
@@ -181,7 +181,7 @@ struct StatsView: View {
|
||||
|
||||
private var topDishes: [DishEntry] {
|
||||
let usage = dishUsage
|
||||
let dishMap = Dictionary(uniqueKeysWithValues: allDishes.map { ($0.id, $0) })
|
||||
let dishMap = Dictionary(allDishes.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
|
||||
return usage
|
||||
.compactMap { id, count in dishMap[id].map { DishEntry(dish: $0, count: count) } }
|
||||
.sorted { $0.count > $1.count }
|
||||
@@ -192,8 +192,8 @@ struct StatsView: View {
|
||||
private struct TagEntry { let tag: Tag; let count: Int }
|
||||
|
||||
private var tagUsage: [TagEntry] {
|
||||
let dishMap = Dictionary(uniqueKeysWithValues: allDishes.map { ($0.id, $0) })
|
||||
let tagMap = Dictionary(uniqueKeysWithValues: allTags.map { ($0.id, $0) })
|
||||
let dishMap = Dictionary(allDishes.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
|
||||
let tagMap = Dictionary(allTags.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
|
||||
var counts: [UUID: Int] = [:]
|
||||
for plan in weekPlans {
|
||||
for slot in plan.slotList {
|
||||
|
||||
Reference in New Issue
Block a user