I have a managed object with two dates: dateOne and dateTwo and I want to retrieve the dates where dateTwo is older than dateOne.
开发者_StackOverflow社区Right now I am using the following predicate to fetch the objects:
NSArray *objects = nil;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"Object" inManagedObjectContext:context];
request.predicate = [NSPredicate predicateWithFormat:@"dateOne > dateTwo", @""];
objects = [context executeFetchRequest:request error:nil];
[request release];
Sometimes it works, but other times the objects fetched have a dateTwo that is more recent than dateOne. Is there a better way to do something like this?
Thanks!
Perhaps you could add a BOOL property "dateTwoIsOlder" to the entity, then just fetch objects that adhere to that?
Why not just create a fetch request
from core data and not do it programmatically?
精彩评论