为什么核心数据模型URL(modelURL)返回nil? [英] Why is Core Data Model URL (modelURL) returning as nil?

查看:105
本文介绍了为什么核心数据模型URL(modelURL)返回nil?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用XCode创建的CoreDataModel创建一个新项目时,一切都很好。但是,我在项目中添加了核心模型文件和核心数据栈代码。该代码已被正确调用,但是该模型的URL为零。我尝试检查该项目,无法确定是否未正确添加或编译模型文件,或者找不到URL。

When I create a new project with CoreDataModel created by XCode, all is well. However, I added a core model file to my project and the "core data stack" code. The code is properly getting invoked, however, the model's URL is nil. I have tried to examine the project and cannot determine if the model file is not properly added, or compiled, or if the URL just cannot be found.

帮我调试和

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"];

modelUrl返回为 nil

modelUrl returns as nil.

推荐答案

检查名称是否正确,然后单击文件中的 Model.momd 文件左侧的文件检查器。在右侧的文件属性检查器中,确保将其添加到您正在运行的正确目标上(即,选中目标名称旁边的复选标记)。

Check for correct names, then click on the Model.momd file in the file inspector on the left. In the file attributes inspector on the right make sure it is added to the correct target you are running (i.e. the checkmark beside your target name is checked).

如果首先找不到该文件,则说明您没有正确将其添加到捆绑软件中。

If you cannot find the file in the first place, you have not added it to the bundle correctly. Drag it from the Finder window into your project.

另一个提示:请注意,始终至少有两个文件:目录和模型。但是您看不到是否只有一个模型版本。

Another hint: note that the there are always at least two files: the directory and the model(s) inside. But you cannot see that if there is only one model version.

Model.xcdatamodeld
    Model.xcdatamodel

在将目录添加到项目之前,请确保Finder中的两个文件都具有相同的名称。 (目录将显示为单个文件。)

Make sure that both files in the Finder have the same name before adding the directory to your project. (The directory will show up as a single file.)

这篇关于为什么核心数据模型URL(modelURL)返回nil?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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