Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
iPhone example code demonstrating Core Data multi-threading
Objective-C C
branch: master
Failed to load latest commit information.
Classes Flatten project directory structure.
MultiThreadedCoreData.xcdatamodeld Flatten project directory structure.
MultiThreadedCoreData.xcodeproj Flatten project directory structure.
.gitignore
MainWindow.xib Flatten project directory structure.
MultiThreadedCoreData-Info.plist Flatten project directory structure.
MultiThreadedCoreData_Prefix.pch Flatten project directory structure.
Person.h Flatten project directory structure.
Person.m Flatten project directory structure.
README.md Spelling changes
RootViewController.xib Flatten project directory structure.
main.m Flatten project directory structure.

README.md

Overview

This is a sample App to demonstrate Core Data multi-threading for safe updates

The application seeds itself with a Core Data entity and then provides a button to run 2 operations. The NSOperations:

  • update different fields of the same entity
  • take a different amount of time to run (intended to simulate distinct differences caused by networking)
  • attempt to save their changes.

The UI allows one to alter the merge policies that are applied to the NSManagedObjectContext used by the application main thread and by the NSOperations. By looking at the console, you can see which combination of merge policies will work best for your application.

It seems as though the merge policy on the main thread NSManagedObjectContext has no bearing on the outcome of the merge; only the merge policy on the NSManagedObjectContext that performed some changes has any effect.

For usages where different operations update different fields, it is suggested that NSMergeByPropertyObjectTrumpMergePolicy would be a good option. For other usages, one would need to balance up the requirements of the application and consider ways of partitioning updates.

Something went wrong with that request. Please try again.