a5c304e209
- Dish: ingredients [String] (default [], never required) and photoData (externalStorage). Additive SwiftData migration — existing stores unaffected. - ICloudSyncService: sync ingredients (optional in payload so pre-2.0 snapshots still decode); photos deliberately excluded from KV sync (1MB limit). - IngredientGenerator: Foundation Models (iOS 26+) generates localized ingredient lines from the dish name, fully on-device. isAvailable gates the UI affordance on older OS/devices; failures record to Crashlytics and return []. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BkanrydYtrme8wipTzWssG
53 lines
1.5 KiB
Swift
53 lines
1.5 KiB
Swift
import Foundation
|
|
import SwiftData
|
|
|
|
@Model
|
|
final class Dish {
|
|
@Attribute(.unique) var id: UUID
|
|
var name: String
|
|
var descriptionText: String?
|
|
var tagIds: [UUID]
|
|
var createdAt: 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
|
|
}
|
|
}
|
|
}
|