title: MagicalRecord: How to save imported data in background
body: <p>I'm trying to import data into Core Data and save it in a background thread with <em>MagicalRecord</em>.</p>
  
  <p>I'm basically trying to do this:</p>
  
  <pre><code>__block User *user = nil;
  [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext)
  {
       user = [User MR_findFirstOrCreateByAttribute:@"userId" withValue:userId inContext:localContext];
       [user MR_importValuesForKeysWithObject:responseObject];
  }];
  
  [User setCurrentUser:user];
  </code></pre>
  
  <p>User is correct when I'm inside the block. After the block is completed <code>user</code> is a <em>NSManagedObject</em> object, but doesn't have any attributes set.</p>
  
  <p>This, on the other hand, works:</p>
  
  <pre><code>OEUser *user = [OEUser MR_findFirstOrCreateByAttribute:@"userId" withValue:userId];                               
  [user MR_importValuesForKeysWithObject:responseObject];
  [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
  [User setCurrentUser:user];
  </code></pre>
  
  <p>But I want to save it in the background.</p>
  
  <hr>
  
  <p>I also tried this to no avail.</p>
  
  <pre><code>User *user = [User MR_findFirstOrCreateByAttribute:@"userId" withValue:userId];
  [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext)
  {
       User *localUser = [user MR_inContext:localContext];
       [user MR_importValuesForKeysWithObject:responseObject];
  }];
  
  [User setCurrentUser:user];
  </code></pre>
  
  <p>The problem here seems to be that <code>[user MR_inContext:localContext]</code> returns <em>nil</em>.</p>
  
  <p>I'm pretty new to Core Data, so bear with me if I'm missing something obvious.</p>