Core Data model files does not load on rename

前端 未结 6 1036
眼角桃花
眼角桃花 2020-12-29 09:52

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

initWithContentsOfURL returns nil and:

6条回答
  •  既然无缘
    2020-12-29 10:24

    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

    
      
         _XCCurrentVersionName
         YourModelFile.xcdatamodel  <-- Change this to YourNEWModelFile
      
    
    

    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.

提交回复
热议问题