4ffa15b06a
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
54 lines
1.6 KiB
Swift
54 lines
1.6 KiB
Swift
import Foundation
|
|
import SwiftData
|
|
|
|
// CloudKit-compatible (2.0): no unique constraints, inline defaults everywhere.
|
|
@Model
|
|
final class Dish {
|
|
var id: UUID = UUID()
|
|
var name: String = ""
|
|
var descriptionText: String?
|
|
var tagIds: [UUID] = []
|
|
var createdAt: Date = Date()
|
|
var isPriority: Bool = false
|
|
|
|
/// Optional ingredient lines (one per entry, e.g. "200g spaghetti").
|
|
/// Populated lazily — manually or via on-device generation — and only for
|
|
/// the dishes a user actually shops for. Never required to create a dish.
|
|
var ingredients: [String] = []
|
|
|
|
/// Optional dish photo. Stored outside the main store to keep it light and
|
|
/// CloudKit-friendly.
|
|
@Attribute(.externalStorage) var photoData: Data?
|
|
|
|
init(
|
|
id: UUID = UUID(),
|
|
name: String,
|
|
descriptionText: String? = nil,
|
|
tagIds: [UUID] = [],
|
|
createdAt: Date = Date(),
|
|
isPriority: Bool = false,
|
|
ingredients: [String] = [],
|
|
photoData: Data? = nil
|
|
) {
|
|
self.id = id
|
|
self.name = name
|
|
self.descriptionText = descriptionText
|
|
self.tagIds = tagIds
|
|
self.createdAt = createdAt
|
|
self.isPriority = isPriority
|
|
self.ingredients = ingredients
|
|
self.photoData = photoData
|
|
}
|
|
}
|
|
|
|
extension Dish {
|
|
static func stableSortedForDisplay(_ dishes: [Dish]) -> [Dish] {
|
|
dishes.sorted { lhs, rhs in
|
|
if lhs.createdAt != rhs.createdAt {
|
|
return lhs.createdAt > rhs.createdAt
|
|
}
|
|
return lhs.id.uuidString < rhs.id.uuidString
|
|
}
|
|
}
|
|
}
|