This blog helped me! I implemented this for unit test btw.
I still don't know why I had to do this though...
guard let entity = NSEntityDescription.entity(forEntityName: "Task", in: context) else {
XCTFail("❌ Failed to create entity")
return
}
let task = Task(entity: entity, insertInto: context) // This is Task type.
https://developer.apple.com/documentation/coredata/nsentitydescription/1425111-entity
Env: Xcode 16.2