I have an app on which I'm trying to implement unit tests. I'm using swift 2.0, Xcode 7 beta 3 and I have several NSManagedObject subclasses which I'm trying to use in unit tests. I'm having the following problems that are preventing me from properly testing...
I'm creating an instance of my class and inserting the newly created object with the following line of code:
let entityName = NSEntityDescription.insertNewObjectForEntityForName("EntityName", inManagedObjectContext: context) as! EntityName
I'm using the NSManageObject generated subclasses with the Module set to the default "Current Product Module".
If I use the defaults without changing anything I get the following error:
Could not cast value of type 'NSManagedObject_EntityName_' (0x7a990b30) to 'AppName.EntityName' (0x101c2ee8).
If I run the code in test mode I get this error:
Could not cast value of type 'NSManagedObject_EntityName_' (0x7a990b30) to 'AppNameTests.EntityName' (0x101c2ee8).
If I blank out the Module for my entities so the placeholder says "None", the app runs fine while debugging and using on a device, but when testing I get the following error:
Could not cast value of type 'AppName.EntityName (0x7a0aabe8) to 'AppNameTests.EntityName' (0x1023bee8).
So, how does one define the module for a Core Data NSManagedObject subclass in swift so that it can be both run and tested?