CoreData多个NSPersistentContainer实例导致Multiple NSEntityDescriptions +entity unable disambiguate的解决

Posted 大熊猫侯佩

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CoreData多个NSPersistentContainer实例导致Multiple NSEntityDescriptions +entity unable disambiguate的解决相关的知识,希望对你有一定的参考价值。



问题现象

在Unit Test中,我们往往需要单独纯净的CoreData数据容器,它需要和App实际业务逻辑使用的数据容器分开,这样可以保证测试数据无污染。

如果使用多个数据容器(NSPersistentContainer或NSPersistentCloudKitContainer),稍不留神就会出现CoreData自定义托管类重复创建的错误提示:

AppName[22519:688276] [error] warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass ‘你的托管类名’ so +entity is unable to disambiguate.

如上,在使用多个CoreData数据容器后,CoreData会抱怨你托管类的描述对象NSEntityDescriptions被重复创建了。

这是怎么回事呢?

在本篇博文中我们会讨论该错误产生的原因以及如何解决它。

还等什么呢?Let’s find out!



问题分析

1. C

以上是关于CoreData多个NSPersistentContainer实例导致Multiple NSEntityDescriptions +entity unable disambiguate的解决的主要内容,如果未能解决你的问题,请参考以下文章

以一个名称将多个对象保存到 coredata

CoreData - 如何在一对多关系中添加多个对象

如何在 CoreData 中保存多个条目?

使用多个实体进行 CoreData 编程

从 CoreData 获取多个实体

如何以一个名称将多个对象保存到 CoreData