wI am using three fetch controllers in order to filter three lists of tasks; today’s, tomorrow’s and finally later tasks. For that case, I have three predicates:
NSPredicate *todayPredicate = [NSPredicate predicateWithFormat:@"(date <= %@) AND isDone == 0",
[self getEndDateForDay:P_Section_Today]];
NSPredicate *tomorrowPredicate = [NSPredicate predicateWithFormat:@"((date >= %@) AND (date <= %@)) AND isDone == 0",
[self getStartDateForDay:P_Section_Tomorrow],
[self getEndDateForDay:P_Section_Tomorrow]];
NSPredicate *laterPredicate = [NSPredicate predicateWithFormat:@"date >= %@ AND isDone == 0",
[self getStartDateForDay:P_Section_Later]];
I was happy with it. It worked like a charm. Until, over a night, I faced the following problem. The three controllers do not update themselves.
Example:
– Started the app on Sunday. (Now, today is Sunday.).
– The app is still running.
– Opened the app on Monday morning.
– Added a new task for Monday. It shall appear in Today’s task, right? No!, it appears in Tomorrow’s tasks. No fix for that except to close the app from the background and launch it again.
I did thought that the performFetch does update the fetch controller along with its predicate, but it doesn’t. Is there a fix for that?
The date in the predicates is fixed when you create them, i.e., your
getStartDateForDay:andgetEndDateForDay:will not get called again automatically. You need to update the predicates when you detect that the day has changed.