I'm attempting to get a list of to-do lists that have to-dos >= a certain date.
Data Model: Todolist has many Todos.
due_at field in Todo model is a Date object.
This is the fetch request I'm using and it keeps crashing.
NSDate *now = [NSDate date];
int daysToAdd = _dueDateSlider.intValue;
NSDate *datePeriod = [now dateByAddingTimeInterval:60*60*24*daysToAdd];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Todolist"];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"todos.due_at >= %@", datePeriod];
NSError *error = nil;
NSArray *todolists = [managedObjectContext executeFetchRequest:request error:&error];
The error I am receiving is:
-[__NSArrayI compare:]: unrecognized selector sent to instance 0x1018a4c50
An uncaught exception was raised
I'm not sure why this is happening, as any other predicate search works fine.
todos.due_at != nil is fine as well as
todos.content like '%test%' works fine.
To get the lists that have any to-dos >= a certain date, use
[NSPredicate predicateWithFormat:@"ANY todos.due_at >= %@", datePeriod];