title: Saving Core Data on seperate thread with Magic Record
body: <p>I am using Magical Record to help with core data saving and multi threading.</p>
  
  <p>I kick off a new thread with GCD. In that new thread, I check if an Entity exists; if it does not I want to create a new one and save it.</p>
  
  <p>Will <code>saveUsingCurrentThreadContextWithBlock^(NSManagedObjectContext *localContext){}</code> return to the main thread to save if it is called on a non-main thread?</p>
  
  <p>or should i just pass the context to the new thread?</p>
  
  <p>EDIT:</p>
  
  <p>On the main thread, I create a MBProgress indicator and create a new thread:</p>
  
  <pre><code>MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.mapView animated:YES];
  
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  
      Person *person = [Person MR_findFirstByAttribute:NAME withValue:self.user.username];
  
      if (person == NULL) {
          NSLog(@"SEPERATE THREAD | person %@ does not exist, creating", self.user.username);
          person = [Person MR_createEntity];
          person.name = self.user.username;
          person.uid = self.user.UID;
  
          [[NSManagedObjectContext MR_contextForCurrentThread] MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
              [MBProgressHUD hideHUDForView:self.mapView animated:YES];
  
              Person *person = [Person MR_findFirstByAttribute:NAME withValue:self.user.username];
  
              if (person) {
                  NSLog(@"COMPLETION BLOCK | person exists: %@", person.name);
              }
          }];
      }
      else {
          NSLog(@"SEPERATE THREAD | person %@ does", self.user.username);
  
              dispatch_async(dispatch_get_main_queue(), ^{
                  [MBProgressHUD hideHUDForView:self.mapView animated:YES];
              });
      }
  });
  </code></pre>
  
  <p>(this method of saving is not persistence, I restart the app and I can't find the Person entity):</p>
  
  <pre><code>2013-03-12 14:25:44.014  SEPERATE THREAD | person iDealer does not exist, creating
  2013-03-12 14:25:44.014  SEPERATE THREAD | thread: &lt;NSThread: 0x84ca720&gt;{name = (null), num = 4}
  2013-03-12 14:25:44.015  -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x840ec30) → Saving &lt;NSManagedObjectContext (0x840ec30): *** UNNAMED ***&gt; on *** BACKGROUND THREAD ***
  2013-03-12 14:25:44.015  -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x840ec30) → Save Parents? 0
  2013-03-12 14:25:44.015  -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:](0x840ec30) → Save Synchronously? 0
  2013-03-12 14:25:44.016  -[NSManagedObjectContext(MagicalRecord) MR_contextWillSave:](0x840ec30) Context UNNAMED is about to save. Obtaining permanent IDs for new 1 inserted objects
  2013-03-12 14:25:44.132  __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke21(0x840ec30) → Finished saving: &lt;NSManagedObjectContext (0x840ec30): *** UNNAMED ***&gt; on *** BACKGROUND THREAD ***
  2013-03-12 14:25:44.134  COMPLETION BLOCK | thread: &lt;NSThread: 0x8435f30&gt;{name = (null), num = 1}
  2013-03-12 14:25:44.134  COMPLETION BLOCK | person exists: iDealer
  </code></pre>