Search code examples
swiftmacosnsfetchedresultscontrollernsmanagedobjectcontext

How to notify the fetched results controller of one target about the changes happened in managed object context of another target?


There are two targets running parallely which share a common databse. Let's say I have created an object using context of target1 and added it to the database. How do I update the NSFetchedResultsController in target2 about the change happened?


Solution

  • A change made by another process is called a remote change, it can be handled in two ways:

    1. mergeChangesFromRemoteContextSave however if the 1st app makes a huge change to its context then you might not want to merge all of that data into the second app's context, hence why Apple have added the next option.
    2. Persistent history tracking allows you to filter the changes made to the database by the first app and only import ones to the second app's context that are relevant to current views or FRCs.