core-data icon indicating copy to clipboard operation
core-data copied to clipboard

Why is notifyAboutChangedObjects called when sync context did save?

Open evandelaney opened this issue 7 years ago • 1 comments

When we receive a did-save notification, we call notifyAboutChangedObjects(from notification:), which, in turn, calls processChangedLocalObjects(_:). That method will then distribute the objects to all change processors

Calling notify... happens on did-save notifications for both MOCs (view and sync).

I see why this is done for the view context; after merging the changed MOs into the sync context, we want to send them along to the change processors where presumably they will be uploaded to CloudKit by MoodUploader.

But, I do not understand why notify... is called when the sync MOC did-save. The remap calls should be mostly a no-op; there's an early return:

guard unmappedMO.managedObjectContext !== context else { return unmappedMO }

I believe the change processors are also a no-op since there's nothing more do download or upload. Am I correct about the no-op on the change processors? Is this by design? Why?

Aside: Could there be situations where saves are called back-to-back and an upload change processor didn't finalize the Mood upload by setting its remoteIdentifier property?

evandelaney avatar Jun 10 '18 17:06 evandelaney

https://github.com/objcio/core-data/issues/26#issuecomment-308681220

davidfrog avatar Apr 16 '20 15:04 davidfrog