I have a CoreData entity with a date attribute and a computed property called 'month'. The month is computed with this method in the entity class:
var month: String {
get {
let dayTimePeriodFormatter = NSDateFormatter()
dayTimePeriodFormatter.dateFormat = "YYYY, MMMM"
let dateString = dayTimePeriodFormatter.stringFromDate(self.date!)
return dateString
}
}
The fetched result controller is set up with this method:
func loadDataSourceForProductionMonthHistory(month: String){
let suppliersFetchRequest = NSFetchRequest(entityName: "Production_Day")
let sortDesciptor = NSSortDescriptor(key: "date", ascending: true)
suppliersFetchRequest.predicate = NSPredicate(format: "month = %@", month)
suppliersFetchRequest.sortDescriptors = [sortDesciptor]
fetchedResultsController = NSFetchedResultsController(fetchRequest: suppliersFetchRequest, managedObjectContext: self.context, sectionNameKeyPath: nil, cacheName: nil)
fetchedResultsController.delegate = self
do {
try fetchedResultsController.performFetch()
} catch {
print("Error occured with FRC")
}
}
And the error thrown is:
2016-06-10 15:25:55.788 Stock Controller[11404:834892] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath month not found in entity <NSSQLEntity Production_Day id=11>'
Is it possible to filter with a predicate on a computed property? I had been using the computed property to create section headers for grouping so thought it would work for this?
I could just create a month attribute but hoping I can avoid and extra attribute that has to be maintain just for filtering.