在任何模型中,没有NSEntityDescriptions声明NSManagedObject子类 [英] No NSEntityDescriptions in any model claim the NSManagedObject subclass

查看:72
本文介绍了在任何模型中,没有NSEntityDescriptions声明NSManagedObject子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CoreData的新手,我正在尝试创建一种缓存机制,其中从API解析对象之后,我将它们保存到数据模型中,然后再次获取它以在tableview上显示它.我正在尝试使用 NSFetchedResultsController 来获取它.在初始化 NSFetchedResultsController 时,我遇到了此运行时异常:

I am new to CoreData and I'm trying to create a caching mechanism wherein after parsing objects from the API, I save them to the data model then fetch it again to show it on the tableview. I'm trying to fetch it using NSFetchedResultsController. Upon initialization of the NSFetchedResultsController, I'm encountering this runtime exception:

2018-12-09 15:03:20.493509+0800 [5184:148001] [error] error: 
No NSEntityDescriptions in any model claim the NSManagedObject subclass 
'Product' so +entity is confused.  Have you loaded your 
NSManagedObjectModel yet ?
CoreData: error: No NSEntityDescriptions in any model claim the 
NSManagedObject subclass 'Product' so +entity is confused.  Have you 
loaded your NSManagedObjectModel yet ?
2018-12-09 15:03:20.493718+0800[5184:148001] [error] error: + 
[Product entity] Failed to find a unique match for an 
NSEntityDescription to a managed object subclass
CoreData: error: +[Product entity] Failed to find a unique match for an 
NSEntityDescription to a managed object subclass

可能是什么原因?

推荐答案

如果使用SwiftUI遇到与此类似的问题,则可以尝试从 Global Namespace更改实体的类 module 当前产品模块.

If you ever encounter an issue similar to this using SwiftUI, you can try changing the entity's class module from Global Namespace to Current Product Module.

转到您的xcdatamodeld文件,然后选择有问题的实体.然后在数据模型检查器中,通过单击字段右侧的箭头,将模块"字段从默认的 Global名称空间更改为可用值当前产品模块".

Go to your xcdatamodeld file and select the problematic entity. Then in the data model inspector, change the Module field from the default Global namespace to available value "Current Product Module" by clicking on the arrow at the right of the field.

这使我的应用可以编译而不会遇到错误.

This allowed my app to compile without encountering the error.

这篇关于在任何模型中,没有NSEntityDescriptions声明NSManagedObject子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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