Multiple NSPersistentContainer instances of CoreData cause Multiple NSEntityDescriptions +entity unable to disambiguate solution

insert image description here



problem phenomenon

In Unit Test, we often need a separate and pure CoreData data container, which needs to be separated from the data container used by the actual business logic of the App, so as to ensure that the test data is not polluted.

If you use multiple data containers (NSPersistentContainer or NSPersistentCloudKitContainer), an error message that the CoreData custom managed class is repeatedly created will appear if you are not careful:

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

As above, after using multiple CoreData data containers, CoreData will complain that the description object NSEntityDescriptions of your managed class is duplicated.

What's going on here?

In this blog post we will discuss why this error occurs and how to fix it.

What are you waiting for? Let's find out!



problem analysis

1. C

Guess you like

Origin blog.csdn.net/mydo/article/details/123585014