Core data NSPredicate-获取仅限于未来日期的核心数据

Core data NSPredicate-获取仅限于未来日期的核心数据,core-data,nspredicate,Core Data,Nspredicate,我需要检索属性设置为当前日期或未来日期的所有Booking对象。我的代码如下: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(departDate >= %@)", [NSDate date]]; [fetchRequest setEntity:entity]; [fetchRequest setPredicate:predicate]; NSError *error; bookings = [[context e

我需要检索属性设置为当前日期或未来日期的所有
Booking
对象。我的代码如下:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(departDate >= %@)", [NSDate date]];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
NSError *error;
bookings = [[context executeFetchRequest:fetchRequest error:&error] retain];

NSLog(@"curernt date %@", [NSDate date]);

for (Booking *order in bookings) {
    NSLog(@"%@", [NSDate dateWithTimeIntervalSince1970:order.departDate]);
}
但日志显示:

2012-03-06 18:58:24.518 Airline[2201:207] curernt date 2012-03-06 13:28:24 +0000
2012-03-06 18:58:24.520 Airline[2201:207] 2012-03-06 12:37:59 +0000
2012-03-06 18:58:24.528 Airline[2201:207] 2012-03-05 12:55:50 +0000
2012-03-06 18:58:24.529 Airline[2201:207] 2012-03-08 12:55:50 +0000
2012-03-06 18:58:24.530 Airline[2201:207] 2012-03-02 13:07:33 +0000
2012-03-06 18:58:24.531 Airline[2201:207] 2012-04-06 13:13:53 +0000
2012-03-06 18:58:24.532 Airline[2201:207] 2012-01-06 13:13:53 +0000

将检索所有对象,就像没有筛选器一样。有人能告诉我我做错了什么吗?

核心数据支持日期直接作为
NSDate
。自1970年以来,您一直在使用
NSDate
和以秒为单位的日期进行混合

在您的模型中,将sue
departDate
设置为“日期”,然后使用

for (Booking *order in bookings) {
    NSLog(@"%@", order.departDate);
}

在我的数据模型中,
departDate
被设置为
Date
,但是当我生成
NSManagedObject
子类时,我检查了“对原始数据类型使用标量属性”,可能是因为
departData
在我的类中被定义为
NSTimeInterval
。。我将尝试仅将该变量类型更改为
NSDate
,并查看其是否有效。将
DepartDate
的数据类型从NSTimeInterval更改为NSDate是否有效…:)