在重命名时不会加载Core Data模型文件 [英] Core Data model files does not load on rename

查看:135
本文介绍了在重命名时不会加载Core Data模型文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为模型的模型文件。如果我将其重命名为SomeOtherName,它只是不会加载。

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

initWithContentsOfURL 返回nil和:

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

...崩溃,因为它认为在此数组中有nil。

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

我可以重命名我的模型,所以出了什么问题?我不能给你更多的信息,因为我没有:P SomeOtherName模型放在捆绑,它应该加载正好。

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.

感谢

推荐答案

我遇到了同样的问题。这是我如何解决它:

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.

原来模型版本存储在一个单独的plist文件中。

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.

文件: YourNEWModelFile.xcdatamodeld / .xccurrentversion

File: YourNEWModelFile.xcdatamodeld/.xccurrentversion

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

请注意,如果您在开发期间重命名模型文件,强>。要将数据模型迁移到新版本,请遵循Core Data文档。

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.

这篇关于在重命名时不会加载Core Data模型文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆