iOS NSDate Core Data Compare fetch request not working

maybe you can help me. What is wrong with this code:

-(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;

}

the line

fetchedObjs = [[[self managedObjectContext] executeFetchRequest:fetch error:&fetchError] retain]; 

crashes with the error:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "originTime >= 2011-02-28 21:07:37 +0000"'

All the objects are NOT nil and also originDate is a NSDate in the CD database

5
задан Dave DeLong 7 March 2011 в 21:56
поделиться