2.0: CloudKit private-database sync replaces KV snapshot sync
Foundation for 2.1 family sharing (CKShare needs these models + container). SwiftData cannot share across Apple IDs today, so 2.0 ships true multi-device sync for the same account instead: - Models made CloudKit-compatible: dropped @Attribute(.unique) on all 5, inline defaults on every attribute, WeekPlan.slots stored as optional relationship (name preserved → lightweight migration) with non-optional slotList facade; ~73 call sites renamed. - Container: cloudKitDatabase .automatic, falling back to the local-only store when CloudKit is unavailable; failures recorded to Crashlytics. - Entitlements: iCloud CloudKit service (container already existed); remote-notification background mode for push-driven sync. - Legacy KV snapshot sync (ICloudSyncService) stays inert when CloudKit is active — kept only for 1.x devices. - DeduplicationService collapses cross-device duplicates deterministically on launch (settings singleton, default tags with tagId remapping, same-week plans). - Note: AppSettings.isPremium now syncs across same-Apple-ID devices; StoreKit (PremiumSyncService + Transaction.updates) remains the source of truth and reconciles on every launch/foreground. All 21 unit tests pass, including ICloudSyncPremiumIsolationTests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BkanrydYtrme8wipTzWssG
This commit is contained in:
@@ -130,14 +130,14 @@ struct StatsView: View {
|
||||
// MARK: - Computed stats
|
||||
|
||||
private var plannedWeeks: [WeekPlan] {
|
||||
weekPlans.filter { plan in plan.slots.contains { $0.dishId != nil } }
|
||||
weekPlans.filter { plan in plan.slotList.contains { $0.dishId != nil } }
|
||||
}
|
||||
|
||||
private var weeksWithAnyDish: Int { plannedWeeks.count }
|
||||
|
||||
private var completeWeeks: Int {
|
||||
weekPlans.filter { plan in
|
||||
!plan.slots.isEmpty && plan.slots.allSatisfy { $0.dishId != nil || $0.isEatingOut }
|
||||
!plan.slotList.isEmpty && plan.slotList.allSatisfy { $0.dishId != nil || $0.isEatingOut }
|
||||
}.count
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ struct StatsView: View {
|
||||
private var dishUsage: [UUID: Int] {
|
||||
var counts: [UUID: Int] = [:]
|
||||
for plan in weekPlans {
|
||||
for slot in plan.slots {
|
||||
for slot in plan.slotList {
|
||||
if let id = slot.dishId { counts[id, default: 0] += 1 }
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ struct StatsView: View {
|
||||
let tagMap = Dictionary(uniqueKeysWithValues: allTags.map { ($0.id, $0) })
|
||||
var counts: [UUID: Int] = [:]
|
||||
for plan in weekPlans {
|
||||
for slot in plan.slots {
|
||||
for slot in plan.slotList {
|
||||
guard let dishId = slot.dishId, let dish = dishMap[dishId] else { continue }
|
||||
for tagId in dish.tagIds { counts[tagId, default: 0] += 1 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user