我有两种模式,一种是Bonsai,另一种是任务:
@Model
final class BonsaiModel {
var uuid: UUID
var timestamp: Date
var purchased: Date
var price: Int
var name: String
var isFavorite: Bool
var age: Int
@Attribute(.externalStorage)
var bonsaiImageData: Data?
@Relationship(deleteRule: .nullify, inverse: CategoryModel.bonsai)
var category: CategoryModel?
@Relationship(deleteRule: .nullify, inverse: SpeciesModel.bonsai)
var species: SpeciesModel?
@Relationship(deleteRule: .cascade, inverse: TaskModel.bonsai)
var newTaskModel: [TaskModel] = []
@Relationship(deleteRule: .cascade, inverse: BonsaiImageModel.bonsai)
var bonsaiImages: [BonsaiImageModel] = []
init(name: String = "",
isFavorite: Bool = false,
bonsaiImageData: Data? = nil
) {
self.uuid = UUID()
self.timestamp = Date()
self.purchased = Date()
self.price = Int()
self.name = name
self.isFavorite = isFavorite
self.age = 2023
self.bonsaiImageData = bonsaiImageData
}
}
@Model
final class TaskModel {
var uuid: UUID
var name: String
var timestamp: Date
var isComplete: Bool
@Relationship(deleteRule: .nullify, inverse: CareTypeModel.newTask)
var careType: CareTypeModel?
var isDue: Date
var bonsai: BonsaiModel?
init(
name: String = "",
isComplete: Bool = false
){
self.uuid = UUID()
self.name = name
self.timestamp = Date()
self.isComplete = isComplete
self.isDue = Date()
}
}
一个博尼赛人可以承担多重任务。 一切产品都进行罚款。
现在,我要显示几天,直到下一个给某个博尼赛的任务到期。
在我的看法中(令人满意) 我获得这样的数据:
@Environment(.locale) private var locale
@State var bonsai = BonsaiModel() // To get me one Bonsai.
@Query private var taskModel: [TaskModel] // To get all Tasks.
My thought was, to get all tasks, then filter tasks to get given Bonsai. Next get the isDue date and in the end, task-date minus actual date equals days left until task.
我曾经有过过滤器,但我没有这样做。 是否有解决办法?