title: Multi Context CoreData with Threads
body: <hr>
  
  <p><strong>UPDATE :</strong> I suppose the issue is that the parent context is not updated when the child context is saved. Still, need help.</p>
  
  <hr>
  
  <p>I have tried many examples of Multi-context (Parent-Child) Core Data. </p>
  
  <p>Previously my app was using the traditional way of storing data, i.e. I used an OperationQueue where I fetch the data from the server and save to the DB using a MOC and on saving fire a notification to the mainMOC to mergeChanges : NSManagedObjectContextDidSaveNotification.</p>
  
  <p>Without disturbing the flow of the app, (i.e. removing the OperationQueue), I tried to implement the Parent-Child ManagedObjectContext Relationship where I used a privateMOC with concurrencyType as <code>NSPrivateQueueConcurrencyType</code> which has a persistantStoreCoordinator, and the mainMOC with concurrenyType as <code>NSMainQueueConcurrencyType</code> which is a child of the privateMOC. And in the Queue I have a tempMOC with concurrencyType as <code>NSPrivateQueueConcurrencyType</code> which is a child of the mainMOC.</p>
  
  <p>While saving, I nest the <code>performBlock</code> of the three MOCs as - </p>
  
  <pre><code>[tempMOC performBlock:^{
          if (![tempMOC save:&amp;error]) {
              NSLog(@"Error : %@",error);
          }
          [mainMOC performBlock:^{
              if (![mainMOC save:&amp;error]) {
                  NSLog(@"Error : %@",error);
              }
              [privateMOC performBlock:^{
                  if (![privateMOC save:&amp;error]) {
                      NSLog(@"Error : %@",error);
                  }
              }];
          }];
      }];
  </code></pre>
  
  <p>I am getting Errors like CoreData 1560 and 1570 while the mainMOC is trying to save. <code>NSValidationErrorKey</code>error where it says some value is <code>nil</code>.
  Is it that the changes of the tempMOC are not going to the mainMOC ? I did not dig in but as far as I know, it should not be nil.
  What could possibly be the error? Please Help.</p>
  
  <p><strong>UPDATE :</strong> I tried to print the objects of tempMOC and I see proper values like :</p>
  
  <pre><code>&lt;Element_Name: 0xc0b59c0&gt; (entity: Element_Name; id: 0xc07ca90 &lt;x-coredata:///Element_Name/t2DCD57A8-4C1A-4AF7-A10E-5B9603E2BB8730&gt; ; data: {
      tag1 = nil;
      tag2 = 3430065;
      tag3 = 600;
      tag4 = N;
      tag5 = "2013-10-29 00:00:00 +0000";
      tag6 = nil;
      tag7 = 327842701;
      relation = "0xbf1f760 &lt;x-coredata://87C54A94-701E-4108-826E-4D98A53380F9/Relation/p1&gt;";
      tag8 = "Some_Value";
  </code></pre>
  
  <p>I tried to print the objects of mainMOC and I see <code>nil</code> value instead of the data like :</p>
  
  <pre><code>&lt;Element_Name: 0xbd47a50&gt; (entity: Element_name; id: 0xc0b14b0 &lt;x-coredata:///Element_Name/t2DCD57A8-4C1A-4AF7-A10E-5B9603E2BB8740&gt; ; data: {
      tag1 = nil;
      tag2 = nil;
      tag3 = 0;
      tag4 = nil;
      tag5 = nil;
      tag6 = nil;
      tag7 = nil;
      relation = "0xbd586c0 &lt;x-coredata://87C54A94-701E-4108-826E-4D98A53380F9/relation/p1&gt;";
      tag8 = nil;
  </code></pre>