我有一个简单的模型,代表日餐和培训课程。我遇到了从CoreData获取Day的问题。我收到以下错误。
2011-11-14 11:41:44.999 CalorificCounter[21002:fb03] -[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x6a6d1a0
2011-11-14 11:41:45.001 CalorificCounter[21002:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x6a6d1a0'
代码
-(Day *)getDayForDate:(NSDate *)date
{
Day *day;
date = [self dateAtStartOfDay:date];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Day"
inManagedObjectContext:[self managedObjectContext]];
//Find the object that matches the given date from a predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date == \"%@\"",date];
[request setEntity:entity];
[request setPredicate:predicate];
//Try to fetch
NSError *error;
NSArray *result = [[self managedObjectContext] executeFetchRequest:request
error:&error ] ;
执行获取请求时发生错误。我已经跟踪执行,一切似乎都是正确的类型(至少我从来没有传递过字符串)。提前谢谢。
更新不要将谓词日期放在引号
中NSPredicate *predicate = [NSPredicate predicateWithFormat:@"date == %@",date];
答案 0 :(得分:0)
将字符串分配给日期对象时会发生此问题。检查日期值并返回NSDate对象