I have Event model with startDate and endDate. I want to sort this event to 3 categories.
- Current: startDate < today < endDate
- Upcoming: today < startDate
- Past: endDate < today
I made a transient property called status contain above logic and use this as parameter in NSFetchedResultsController
NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: "status", cacheName: nil)
When I run I got this error telling me to use section as sort descriptor.
CoreData: error: (NSFetchedResultsController) The fetched object at index 2 has an out of order section name '1. Objects must be sorted by section name'
I then set this in sort descriptor and got this error, since transient can't be used as sort descriptor.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath status not found in entity '
The problem is this section are determine from 2 properties, so it can't be sort by just startDate or endDate, but both.
What is the best way to solve this problem? I have consider making this status non-transient, but this value is updated daily, I think it kind of weird to make it non-transient.