title: Removing and adding persistent stores to a core data application
body: <p>I'm using core data on an iPhone application. I have multiple persisntent stores that I'm switching from one to another so that only one of the stores can be active at the time. I have one managed object context and the different persistent stores are similar in data format (sqlite) and share the same managed object model.</p>
  
  <p>I'm importing the data to each persistent store from a respective XML file. For the first import everything works fine, but after I remove the imported data (the persistent store and the physical file) and then re-import, core data gives me an error:</p>
  
  <pre><code>*** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'The NSManagedObject with ID:0x3c14e00 &lt;x-coredata://6D14F11E-2EA7-4141-9BE8-53747DE6FCC6/Book/p2&gt; has been invalidated.'
  </code></pre>
  
  <p>This error comes from the save: of NSManagedObjectContext. Before re-importing, i'm removing the persistent store from the persistent store coordinator and removing the physical file, so everything should be as if re-importing was done for the first time. Alos, the objects in managed object context are removed and the context is sent the reset: message (I don't know if this is actually needed).</p>
  
  <p>Could some one help me out here? How should the persistent store be switched?</p>
  
  <p>I'm basically using the same logic as tutored here: <a href="http://blog.sallarp.com/iphone-core-data-uitableview-drill-down/" rel="nofollow noreferrer">http://blog.sallarp.com/iphone-core-data-uitableview-drill-down/</a></p>
  
  <p>Thanks in advance.</p>
  
  <h2>Update on the goal</h2>
  
  <p>Thank you for your answers.</p>
  
  <p>Apologies for the vagueness on my goal. I'm developing a Bible reader application that would import translations from XML to core data SQL. Currently only one translation can be in use. Currently I only have different MOC and PS for each translation since the model is the same. I do believe, however, if you say that the stack should be created as a whole. The translations have no connections between each other, so there is no actual reason for using the same stack. The only thing that could complicate this would be notes/bookmarks/etc that will reference to the active translation. The references, however, will be textual so again there is no necessary need for a shared stack.</p>
  
  <p>Thank you for your input.</p>