I have a SectionedFetchRequest
that almost works as expected.
My data model has two Entities (Item
and Attribute
). Both entities have a name
attribute and an order
attribute. The Attribute
entity has a to-One relationship to an Item
called item.
The Attribute
entity also has a computed property:
@objc var sectionName: String {
get { return self.item.name }
The SectionedFetchRequest's sectionIdentifier
key is \Attribute.sectionName
and the sortDescriptors
keys are \Attribute.item.order
and then \Attribute.order
. This sorts groups of Attribute's into Sections ordered by the Attribute
item's order
property. Each section is then ordered by the Attribute's own order
property.
As expected, when the order
property of any Attribute
object in the results changes, that section of the View is updated to reflect the change. However, if any of the Attribute's related Item order
properties change, the View is not updated.
It almost seems like SectionedFetchRequest
is handling the
NSManagedObjectContextDidSave
notifications for changes to Attribute
objects, but ignoring changes to Item
objects that that should cause the results order to be changed and therefore the View to be updated.
Is this a bug in SectionedFetchRequest
or is there a direct way that I can get the SectionedFetchRequest
to change its state so SwiftUI can update the View as expected?
When I make a change to an Item's order, I can force the results to be updated by dynamically changing the nsPredicate
with something that's different, but something that does not actually change the results. However, it seems like there should be a more appropriate way to force the SectionedFetchRequest
to update the order of the Sections even if no changes are made to the actual Attribute
objects that fetched.