Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data model files does not load on rename

I have a model file thats named "Model". If I rename it to "SomeOtherName" it just does not get loaded.

initWithContentsOfURL returns nil and:

mergedModelFromBundles: [NSArray arrayWithObjects:[NSBundle mainBundle], nil]; 

...crashes with because it thinks there is nil in this array.

I am allowed to rename my model so whats wrong? I can not give you more info because I have none :P The SomeOtherName model is placed in the bundle and it should load just fine.

Thanks

like image 504
david Avatar asked Aug 12 '11 18:08

david


1 Answers

I just ran into the same problem. Here is how I solved it:

Renaming the model file alone is not enough, because it does not rename the reference to the current model version.

It turns out the model version is stored in a separate plist file. Simply open it in a text editor and change the old name to your new model file name.

File: YourNEWModelFile.xcdatamodeld/.xccurrentversion

<plist version="1.0">
  <dict>
     <key>_XCCurrentVersionName</key>
     <string>YourModelFile.xcdatamodel</string>  <-- Change this to YourNEWModelFile
  </dict>
</plist>

Please note that you should only do this if you rename the model file during development. For migrating your data model to a new version, follow the Core Data docs.

like image 68
Mark Avatar answered Sep 21 '22 15:09

Mark