I have an entity with three fields
Task {
Active BOOL
Recurrent Int
Started date
}
‘Recurrent’ is the delay for a task to happen. If task has a given ‘Started’ and a ‘Recurrent’ of 15, means it have to be repeated 15 days after ‘Started’.
I want to build an NSPredicate for finding all entities that at a given date need to be executed.
For example supposing there’s one entity in store with ‘Started’ = 15/12/2011 ‘Recurrent’ = 15, then querying CoreData on 29/12/2011 give no result. Doing a query on 30/12/2011 will give a result because 15 days has passed since ‘Started’.
I would easily deal with this with SQL with some math operation but I have absolutely no idea on how to accomplish this using NSPredicate, considering that the query is done directly on field.
I would like to stay with NSPredicate because it’s an iOS application with UITableView and I am planning to use an NSFetchedResultsController, but if not possible, an NSArray of entities would be fine.
thanks
The “easy” answer would be to store
recurrentas a date as well. Or to store arecurrentResolvedvalue that is a date and fetch against that.The less easy and uglier option is to load all tasks and do the calculation in memory (in a convenience method) and then do a second
NSPredicateagainst the objects. Once they are loaded into memory yourNSPredicatecan take advantage of methods in your subclass.I would recommend the first option. The second is far more expensive.