我正在尝试显示swiftui coredata中仅有的今天或最近24小时输入数据的列表。我不知道语法或逻辑如何获取@FetchRequest谓词上的当日数据。有人可以帮忙,这是显示所有数据的代码
@FetchRequest(
entity: ExpenseLog.entity(),
sortDescriptors: [
NSSortDescriptor(keyPath: \ExpenseLog.date, ascending: true)
]
//,predicate: NSPredicate...
)
private var result: FetchedResults<ExpenseLog>
...
ForEach(self.result)
{
(log: ExpenseLog) in
ZStack{
HStack(spacing: 16) {
CategoryImageView(category: log.categoryEnum)
VStack(alignment: .leading, spacing: 8) {
Text(log.nameText).font(.headline)
Text(log.dateText).font(.subheadline)
}
Spacer()
Text(log.amountText).font(.headline)
} .padding(.vertical, 8) .padding(.horizontal,4)
}
}
答案 0 :(得分:0)
只需使用以下内容过滤列表
Calendar.current.isDateInToday(yourDate)
Calendar.current.isDateInYesterday(yourDate)