在核心数据中使用特定NSDate进行搜索的问题

时间:2011-08-03 20:41:35

标签: ios core-data nsdate

我使用以下代码在Core Data中搜索特定的日期条目:

            //NSDate *tempDate=<a date element fetched from a core data query>

            NSManagedObjectContext *context=[self managedObjectContext];
            RecentMovieInfo *recent3 = nil;
            request = [[NSFetchRequest alloc] init];

            entity=[NSEntityDescription entityForName:@"RecentMovies" inManagedObjectContext:context2];
            [request setEntity:entity];

            [request setPredicate:[NSPredicate predicateWithFormat:@"DateTime=%@",tempDate]];

            recent3 = [[context2 executeFetchRequest:request error:&error] lastObject];

但是,我收到以下错误:

2011-08-03 15:28:59.573 EncameoApp[2447:707] -[__NSArrayI timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x2c4640
2011-08-03 15:28:59.641 EncameoApp[2447:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x2c4640'

任何帮助?

1 个答案:

答案 0 :(得分:0)

如何设置tempDate?您确定它是NSDate而不是NSArray吗?

您收到的错误表示您尝试在类上调用选择器timeIntervalSinceReferenceDate(在这种情况下为__NSArrayI),但不响应该选择器。