我是 CoreData 的新手,我正在尝试创建一种缓存机制,其中在从 API 解析对象后,我将它们保存到数据模型中,然后再次获取它以在 TableView 上显示它。我正在尝试使用 NSFetchedResultsController
获取它。在初始化 NSFetchedResultsController
时,我遇到了这个运行时异常:
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 时遇到与此类似的问题,您可以尝试将实体的类 module 从 Global Namespace 更改为 Current Product Module.
转到您的 xcdatamodeld 文件并选择有问题的实体。然后在数据模型检查器中,通过单击字段右侧的箭头将模块字段从默认的全局命名空间更改为可用值“当前产品模块”。
这让我的应用程序可以编译而不会遇到错误。
关于ios - 任何模型中的 NSEntityDescriptions 都没有声明 NSManagedObject 子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53690712/