37 lines
848 B
Swift
37 lines
848 B
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
|
|
|
|
init(
|
|
id: UUID = UUID(),
|
|
name: String,
|
|
descriptionText: String? = nil,
|
|
tagIds: [UUID] = [],
|
|
createdAt: Date = Date()
|
|
) {
|
|
self.id = id
|
|
self.name = name
|
|
self.descriptionText = descriptionText
|
|
self.tagIds = tagIds
|
|
self.createdAt = createdAt
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|