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

猜你喜欢

转载自blog.csdn.net/mydo/article/details/123585014