I have a SwiftUI view which updates my NSManagedObject subclass object after finishing dragging.
I've noticed that NSFetchedResultsController
is not reporting updates at the end of the run-loop during which the change occurred. It takes a few moments or a save()
to changes being noticed.
To debug it, I've swizzled processPendingChanges
method of NSManagedObjectContext
and logged when it's called.
To my surprise, I've noticed it's not always called at the end of the run loop.
What am I missing here? Why is processPendingChanges()
not called? Should I call it manually on my own after every change?
For reference: I'm testing on macOS in the AppKit app. The NSManagedObjectContext
is created by NSPersistentDocument
.
Here's how my View's code look like:
// `myItem` is my subclass of NSManagedObject
Item()
.gesture(
DragGesture(minimumDistance: 0, coordinateSpace: CoordinateSpace.compositionGrid)
.onChanged({ _ in
// ...
})
.onEnded({ (dragInfo) in
// :-(
// This change is not always noticed by NSFetchedResultsController
//
myItem.someProperty = dragInfo.location
})
)