【发布时间】:2016-01-12 07:49:55
【问题描述】:
我的 CoreData 模型中有一个类型为 Date 的属性。有像
01/01/2012 13:37:00, 01/01/2013 13:37:00, 05/01/2012 13:37:00,..
现在,我想设置谓词应该fetch the dates which has the day 01 and month 01 regardless of the year.
我只能获取谓词中带有between 的日期。
有什么方法可以按日期和月份过滤这些日期吗?
【问题讨论】:
-
通过将
NSDateComponents和NSPredicate与块(predicateWithBlock:)一起使用,您应该可以做到。但是,如果您可能对大量数据执行此操作,那么明确存储一天和一个月可能是一个更好的解决方案。 -
要使用
NSDateComponents,我必须获取所有数据,然后进行比较。 -
糟糕,我忘了我们不能将
predicateWithBlock:与CoreData 一起使用。 -
我已经使用明确添加日期和月份来完成它。
-
& 是的
predicateWithBlock:给出了错误。
标签: ios objective-c core-data