0

I have 3 build configurations, Debug, Release and Development. For Development I have created a new Scheme with a new bundleID, Product name etc so I can see which one is DEV and DEBUG on my phone.

I am using Core Data and for the DEBUG with the original bundleID everything works fine, but when I switch to use the Development one, I get an error when I try to create a new entity with name:

NSEntityDescription.insertNewObject(forEntityName: "MyEntity", into: managedContext)

The error I get:

Could not cast value of type 'NSManagedObject_MyEntity_' (0x600002d62b20) to 'AppName_DEV.MyEntity' (0x102bf9368).

It seems like it is trying to get the MyEntity class from my "AppName DEV" scheme not the "AppName". I can't find any Build Settings where I could point it to use the same model?

Any ideas on how to use core data with multiple build configurations?

kalafun
  • 3,512
  • 6
  • 35
  • 49

1 Answers1

0

Ok, I found the problem. Since I was trying to revive a very old app originally written in swift 2, it occurred to me that I might double check how was the data model created. After hours of tinkering with the core data set up process, I changed 2 things that finally get it to work.

1.) In the .xcdatamodeld file, on the right side in the Data Model Inspector, make sure that you have the Module field EMPTY I had my AppName Inside, which was the same as the original target name.

2.) I added @objc(EntityName) to the NSManagedObject subclass I had.

  • Of course I cleaned the project, deleted the app from the simulator and installed it again.

If you have an issue like that, hope that whis will help you, good luck!

kalafun
  • 3,512
  • 6
  • 35
  • 49