Fetch the records like so
NSManagedObjectContext *moc = …;
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Restaurant"];
NSError *error = nil;
NSArray *results = [moc executeFetchRequest:request error:&error];
if (!results) {
DLog(@"Error fetching Restaurant objects: %@\n%@", [error localizedDescription], [error userInfo]);
abort();
}
Then take the results array and enumerate like so:
NSMutableArray *newerRestaurantsArray = [NSMutableArray alloc] init];
for (id object in results){
//or use a block if you want
NSManagedObject *restaurant = (NSManagedObject *)object;
if (object.dateSaved > date a week ago){
[newRestaurantsArray addObject: object];
}
}
The newRestaurantsArray will have the ones you want. You then have to delete the ones you don't want or delete all of them and just save back the ones you want. Look at this tutorial that shows how to save and make it work for your implementation.
You can also use NSPredicate
to get only the results you want. Check out this SO answer. To see how for your particular case.