When does the NSMergePolicy subclass fit?

I wrote a small structure that synchronizes CoreData objects with an SQL database on my server, and I use a subclass NSManagedObjectto add synchronization-related metadata (for example:) someObject.sync_status = needsSyncto each object. The synchronization procedure is called periodically and changes this metadata in a separate context in the background without involving the user.

If the synchronization procedure is called when the user is actively editing and saving objects in NSManagedObjectContext, the user version of the metadata is likely to be outdated and will conflict with the current metadata stored in the background context. My solution is to listen to and merge the changes from the background context notifications, although I would prefer to avoid this complexity outside the box.

I am wondering if a custom merge policy will allow at the structural level, ignoring the custom version of the metadata properties, and all other properties will obey NSMergePolicyTypeas usual (by default NSErrorMergePolicyType, it will probably be most useful to me). I tried to subclass NSMergePolicyand override resolveConflicts:error:, but I can't figure out how it should work, and I find null examples on the Internet.

My questions are:
 - Am I on the right track with this idea of ​​a merger policy?
 “If so, how do I resolve conflicts within redefinition resolveConflicts:error:?”

Thank!

+4
source share

All Articles