核心数据 - 加载外部存储/错误:'+entityForName: 无法找到实体名称'Place''的 NSManagedObjectModel

发布于 2024-12-20 02:22:15 字数 985 浏览 2 评论 0原文

我有一个利用 Core Data 进行数据持久化的应用程序。我的应用程序由 TabBarController 内的 (4) 个导航控制器组成。导航控制器的根视图控制器是 UITableView 控制器,当您选择一个单元格时,它会在每种情况下显示一个详细信息视图控制器。我希望主应用程序是静态的,这样用户就无法编辑数据,并且我的更新将使用一个单独的应用程序进行,我将使用该应用程序来更新数据,然后发布新版本。

我已经完成了数据申请,它成功保存了数据,我可以将其调用回来显示,一切都显示良好。我还使用 SQlite 数据浏览器查看了数据,以确保一切正常。

然后,我将填充的 .sqlit 文件放入主应用程序的文档目录中,并确保名称匹配,如下所示:

NSURL *storeURL = [[self applicationDocumentsDirectory] ​​URLByAppendingPathComponent:@"RoundTopApp.sqlite"];

执行此操作然后运行应用程序后,我收到以下错误:

'+entityForName:无法找到实体名称“Place”的 NSManagedObjectModel'

我添加了下面的代码以注意我正在使用 NSFetchedResultsController 来执行获取。

  • (void)viewDidLoad { [超级viewDidLoad];

    NSError *错误; if (![[self fetchedResultsController] PerformFetch:&error]) { NSLog(@"未解决的错误 %@, %@", error, [error userInfo]); 退出(-1); // 失败 }

    self.title = @"住宿"; }

我不确定这里出了什么问题。

任何帮助将不胜感激。

哈德逊

I have an application that utilizes Core Data for data persistence. My application is comprised of (4) Navigation Controllers inside a TabBarController. The Navigation Controller's root view controller is a UITableView Controller and when you select a cell it displays a Detail view controller in each case. I wanted the main application to be static so the user cannot edit the data and my update would be made using a separate application that I would use to update the data and then put out a new version.

I have completed the data applications and it successfully saves the data and I can call it back up to display and all appears well. I have also looked at the data with a SQlite Data browser to make certain it is all good.

I then take the populated .sqlit file and place it in the documents directory of the main application and make sure the names match see below:

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"RoundTopApp.sqlite"];

After doing this and then running the application, I get the following error:

'+entityForName: could not locate an NSManagedObjectModel for entity name 'Place''

I have added the code below to note that I am using the NSFetchedResultsController to perform the fetch.

  • (void)viewDidLoad
    {
    [super viewDidLoad];

    NSError *error;
    if (![[self fetchedResultsController] performFetch:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    exit(-1); // Fail
    }

    self.title = @"Lodging";
    }

I am not sure what is wrong here other than I have failed to add it to the application bundle or something.

Any help would be appreciated.

Hudson

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

別甾虛僞 2024-12-27 02:22:15

该错误表示您正在尝试从数据存储中访问名为“Place”的实体,但您在应用程序中定义的托管对象模型不包含此实体。也许您已在创建数据存储的其他应用程序中添加了此实体?如果是这样,您需要更新正在读取数据存储的应用程序中的托管对象模型,以匹配创建存储的应用程序中的模型。

或者,如果您已在两个应用程序之间复制了托管对象模型,并且您只是复制了该模型,则可能需要执行干净构建(产品>干净)。如果您要维护版本化模型,还请确保将新模型设置为当前模型。

The error says that you are trying to access entities called "Place" from your data store, but that the Managed Object Model that you've defined in the app doesn't contain this entity. Perhaps you've added this entity in your other app where you're creating the data store? If so, you need to update the Managed Object Model in the app that is reading the data store to match the model in the app that has created the store.

Alternatively, if you've copied the Managed Object Model between the two apps, and you've only just copied this across, you probably need to do a Clean Build (Product > Clean). Ensure also that your new model is set as the current model, if you're maintaining a versioned model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文