Ios 用于查找自日期后x天的核心数据谓词

Ios 用于查找自日期后x天的核心数据谓词,ios,iphone,objective-c,core-data,nspredicate,Ios,Iphone,Objective C,Core Data,Nspredicate,我有核心数据模型: Book ---- name release_date 我需要从发行日起至少两天内获得所有书籍, 我想用NSPredicate(不要将所有的书都加载到内存中,而是循环检查) 我要找的是这样的东西: NSDate *now = [NSDate date]; NSPredicate *pred = [NSPredicate predicateWithFormat:@"release_date + "48 hours" <= %@", now]; NSDate*now

我有核心数据模型:

Book
----
name 
release_date 
我需要从发行日起至少两天内获得所有书籍,
我想用
NSPredicate
(不要将所有的书都加载到内存中,而是循环检查)

我要找的是这样的东西:

NSDate *now = [NSDate date];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"release_date + "48 hours" <= %@", now];
NSDate*now=[NSDate-date];

NSPredicate*pred=[NSPredicate predicate WITHFORMAT:@“发布日期+“48小时”谓词不会为您更改日期。您应该创建适当的日期(基于当前日期,并使用
NSDateComponents
)并将其传递给谓词。您可以使用
我想您需要这样的内容:

NSDate *date2DaysBefore = [NSDate dateWithTimeIntervalSinceNow:-2*24*3600];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"release_date <= %@", date2DaysBefore];
NSDate*date2DaysBefore=[nsdatedatewithtimeintervalsince:-2*24*3600];

NSPredicate*谓词=[NSPredicate谓词格式:@”发布日期我不想更改日期,我想从发布日期起至少两天内取回所有这些书籍。我会更新问题,使其更清楚我不是说谓词不会更改存储数据中的日期,我是说您需要计算适当的日期并将其传递给谓词,因为它不会更改一天不一定有24小时(想想夏令时转换)。这不是一个精确的答案!!这只是对他问题的可能解决方案的提示。如果我们想要精确,我们应该格式化日期以删除时间组件,因为一本书的发行日期不包含小时和分钟…一天不一定有24小时(想想夏令时转换)。
@"release_date <= %@", now - "48 hours"
NSDate *date2DaysBefore = [NSDate dateWithTimeIntervalSinceNow:-2*24*3600];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"release_date <= %@", date2DaysBefore];