title: Crashes in Core Data's Inferred Mapping Model Creation (Lightweight Migration). Threading Issue?
body: <p>I'm getting random crashes when creating an inferred mapping model (with Core Data's lightweight migration) within my application. By the way, I have to do it programmatically in my application while it is running.</p>
  
  <p>This is how I create this model (after I have made proper currentModel and newModel objects, of course):</p>
  
  <p>NSMappingModel *mappingModel = [NSMappingModel inferredMappingModelForSourceModel:currentModel destinationModel:newModel error:&amp;error];</p>
  
  <p>The problem is this: This method is crashing randomly. When it works, it works just fine without issues. But when it crashes, it crashes my application (instead of returning nil to signify that the method failed, as it should). By randomly, I mean that sometimes it happens and sometimes not. It is unpredictable.</p>
  
  <p>Now, here is the deal: I'm running this method <em>in another thread</em>. More precisely, it is located inside a block that is passed via GCD to run on the global main queue. I need to do this for my UI to appear crisp to the user, i.e. so that I can display a progress indicator while the work is underway.</p>
  
  <p>The strange thing seems to be that if I remove the GCD stuff and just let it run on the main thread, it seems to be working fine and never crashing. Thus, could it be because I'm running this on a different thread that this is crashing?</p>
  
  <p>I somehow find that weird because I don't believe I'm breaking any Core Data rules regarding multi-threading. In particular, I'm not passing any managed objects around, and whenever I need access to the MOC, I create a new MOC, i.e. I'm not relying on any MOC (or for that matter: <em>anything</em>) that has been created earlier on the main thread. Besides the little MOC stuff that occurs, occurs <em>after</em> the mapping model creation method, i.e. <em>after</em> the point at which the app crashes, so it can't possibly be a cause of the crashes under consideration here.</p>
  
  <p>All I'm doing is taking two MOMs and asking for a mapping model between them. That can't be wrong even under threading, now can it?</p>
  
  <p>Any ideas on what could be going on?</p>