I have a Core Data entity with a computed property and I want to sort the objects of this entity by this computed property. So
• I build the NSFetchRequest in the normal way, including an NSSortDescriptor for sorting by this computed property.
• Construct the usual NSFetchedResultController and call performFetch().
This results in a fatal error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath score not found in entity Wine'
I've tried to do this in several different ways, including (a)
@objc public var score: Float {
get {
<getter code here>
}
}
(b) Define score in the data model as transient, then
@objc public var _score: Float {
get {
<getter code here>
}
}
... and ...
public override func awakeFromFetch() {
super.awakeFromFetch()
score = _score
}
But the error persists.
Is there any way to get this to work without abandoning NSFetchedResultsController, fetching unsorted records, sorting them programmatically and building the snapshot from the sorted array of objects? (I know, but it's the best I've been able to come up with so far...)