Correction: the crash does NOT happen in container.loadPersistentStores call. This call completes successfully.
The crash happens when a new document is opened and the document view is being constructed.
After the first document is open:
2021-12-03T11:06:05-0800 debug: in view body, context: <NSManagedObjectContext: **0x60000348dad0>** , class: , hash: **105553171372752** , coordinator: Optional(<NSPersistentStoreCoordinator: **0x6000021a8d00>)** , name: nil , objects: []
2021-12-03T11:06:05-0800 debug: in view onAppear, context: <NSManagedObjectContext: **0x60000348dad0>** , class: , hash: **105553171372752** , coordinator: Optional(<NSPersistentStoreCoordinator: **0x6000021a8d00>)** , name: nil , objects: []
And then when I open a second document:
2021-12-03T11:08:02-0800 debug: in view body, context: <NSManagedObjectContext: **0x6000034a81a0>** , class: , hash: **105553171480992** , coordinator: Optional(<NSPersistentStoreCoordinator: **0x600002198a80>)** , name: nil , objects: []
CoreData: warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'DBObject' so +entity is unable to disambiguate.
So the second view definitely gets a new context and a new coordinator, but CoreData for some reason gets confused with the same entity being loaded twice, even though they belong to two different contexts.
Any idea how to disambiguate the two contexts?