Hello folks.
I'm following the Ultimate Portfolio App videos, and when I get to the part of "Testing Core Data" video, I'm getting a very strange error and I cannot understand why.
The failure
When I get to the part of:
func testDeletingProjectCascadeDeletesItems() throws {
try dataController.createSampleData()
let request = NSFetchRequest<ContactStorage>(entityName: "ContactStorage")
let contacts = try managedObjectContext.fetch(request)
The code is almost the same to the original tutorial (except the entity's name, and the class name.
The fetch request fails, and the output error is "Could not cast value of type MyApp.ContactStorage as MyAppTests.ContactStorage"
I think it's something related to the request or the fetch method, but I have no clue of what it is.
There's a previous test that passes, which includes the "try dataController.createSampleData()"
func testSampleDataCreationWorks() throws {
try dataController.createSampleData()
XCTAssertEqual(dataController.count(for: ContactStorage.fetchRequest()), 6, "There should be 6 sample projects.")
XCTAssertEqual(dataController.count(for: NoteStorage.fetchRequest()), 50, "There should be 50 sample items.")
}
Can anybody point me towards a solution?
The whole code is here: https://github.com/LeTarrask/Dualogue
Thanks.