也許你可以幫助我。有什麼不對這個代碼:iOS NSDate核心數據比較獲取請求不起作用
-(NSMutableArray *)returnItemsWithName:(NSString *)name{
NSFetchRequest *fetch=[[NSFetchRequest alloc] init];
NSEntityDescription *entity=[NSEntityDescription entityForName:@"XYZ" inManagedObjectContext:[self managedObjectContext]];
[fetch setEntity:entity];
NSDate *sevenDaysAgo = [appDelegate dateByAddingDays:-7 toDate:[NSDate date]];
NSPredicate *pred= [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"originTime >= %@", sevenDaysAgo]];
[fetch setPredicate:pred];
NSError *fetchError=nil;
NSMutableArray *fetchedObjs = [[[self managedObjectContext] executeFetchRequest:fetch error:&fetchError] retain];
if (fetchError!=nil) {
return nil;
}
return fetchedObjs;
}
行
fetchedObjs = [[[self managedObjectContext] executeFetchRequest:fetch error:&fetchError] retain];
崩潰,並顯示錯誤:
*終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因:「無法解析格式字符串「originTime> = 2011-02-28 21:07:37 +0000」'
所有的對象都不是零,也是originDat e是在CD數據庫中的NSDate
是「originDate」還是「originTime」字段的名稱? – Anomie 2011-03-07 21:55:41