title: Core Data: Synchronize data accesses with app and contained extension
body: <p>I have a Cocoa application which contains a Today Extension. I use Core Data (SQLite) to store and share data between those two. Both apps share a group container to have access to the same data store. Both applications do not only read but as well write data which leads to problems. At times either of the applications throws an error. I experienced three different error types so far:</p>
  <blockquote>
  <p>Could not merge changes</p>
  </blockquote>
  <hr />
  <blockquote>
  <p>Error in CoreDragRemoveTrackingHandler: -1856</p>
  <p>Error in CoreDragRemoveReceiveHandler: -1856</p>
  </blockquote>
  <hr />
  <blockquote>
  <p>CoreData: error: NULL _cd_rawData but the object is not being turned into a fault</p>
  </blockquote>
  <hr />
  <blockquote>
  <p>Error in CoreDragRemoveReceiveHandler: -1856
  CoreData: error: Serious application error.  Exception was caught during Core Data change processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  -[__NSCFSet addObject:]: attempt to insert nil with userInfo (null)</p>
  </blockquote>
  <p>From the article <a href="https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1" rel="nofollow noreferrer">Sharing Data with Your Containing App</a> in the iOS dev library (this is not iOS/Cocoa-Touch, but OSX/Cocoa - but the same should apply) I have learned:</p>
  <blockquote>
  <p>To avoid data corruption, you must synchronize data accesses. Use Core Data, SQLite, or Posix locks to help coordinate data access in a shared container.</p>
  </blockquote>
  <p>Can someone please point me into a direction what this exactly means?</p>