I have a Swift project using CoreData with installation subclasses of NSManagedObject. They have a class name setting (in the xcdatamodel view), which includes as the main target name "MainTarget.MyEntity" according to. Everything works well when the application starts. However, I went to add some Unit tests using XCTest, and the application crashed with ERR_BAD_ACCESS or ERR_BAD_INSTRUCTION when it returned the result of executeFetchRequest to the appropriate type. I also tried casting every item in the array, and this also causes a crash. The error in all my tests is zero.
var entities = _managedContext.executeFetchRequest(fetchRequest, error: &error) as [MyEntity]?
Above results: "Fatal error: NSArray element could not match Swift Array element type" on the console.
var entities = _managedContext.executeFetchRequest(fetchRequest, error: &error)
let e = entities[0]
let ee = e as NSManagedObject
let eee = e as MyEntity
The above causes a crash, but only when called from unit test!
I have two goals, one main goal and one test goal (normal default setting). NSManagedObject classes are selected for both purposes so that they are available for testing. These subclasses are written in Swift, no Objective-C.
During unit tests, I use persistentStoreCoordinator in memory (although I tried with the same setting in AppDelegate with the same result).
Swift (, ). , executeFetchRequest, , , "po" XCode - SourceKit 3 , ... . , , , TestTarget.MyEntity MainTarget.MyEntity. , MainTarget.MyEnity( MainTarget) , , .
, , unit test , , , . - XCTests NSManagedObject? CoreData MainTarget, , TestTarget?
, , :