ios - 任何模型中的 NSEntityDescriptions 都没有声明 NSManagedObject 子类

标签 ios swift

我是 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 时遇到与此类似的问题,您可以尝试将实体的类 moduleGlobal Namespace 更改为 Current Product Module.

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

这让我的应用程序可以编译而不会遇到错误。

Changing the module field

关于ios - 任何模型中的 NSEntityDescriptions 都没有声明 NSManagedObject 子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53690712/

相关文章:

ios - 除了默认、黑色或白色之外,如何更改 UICollectionView 中滚动条指示器的颜色?

ios - 在 Backendless 中存储一些特殊字符

ios - 在 Apple 批准我的 API 请求之前,我是否可以在我的设备上编译和部署 NEHotspotHelper 项目?

ios - 强制对象存活直到 block 被执行的正确方法

ios - 更新uitableview时断言失败

swift - Firebase 数据库,为什么之前打印 firebase 代码之后的打印行?

swift - 调用此完成处理程序的正确语法是什么?

swift - 在 Collection View 中创建装饰 View 作为自定义列

ios - UIScrollView 中的 UIWebView 具有自动布局

ios - 如何从 UITableViewRowAction 获取对按钮的引用?