runmad
runmad

Reputation: 14886

Core Data object deletion crashes app

I've tried reverting way back in my source code to try and figure out what's causing a serious issue.

When I delete a NSManagedObjects from Core Data my app crashes with the following suggestion:

CoreData`_nameForEntityDescription:

Note that I see the error one of the NSManagedObjects, but not for another NSManagedObjects as well.

I'm using MagicalRecord to take of my Core Data needs, but I am not suspecting this to be the issue. At this point, I very stumped at what the issue could be.

Are there any Core Data experts who might be able to give me any hints as to what the issue may be?

I'm also seeing the exact same issue with _nameForEntityDescription when I try to grab a set of NSManagedObjects for an object (through it's relationship):

NSSet* delSet = [NSSet setWithSet:contact.contactEmails];

So it seems like something is corrupt with the NSManagedObject model, but I've looked through everything I have for it and I cannot see what it would be :(

Upvotes: 0

Views: 601

Answers (1)

casademora
casademora

Reputation: 69647

I've had crashes when deleting objects in the past. Since you don't have enough details here, I'll give you some general things to check:

1) When you delete an object, make sure you have no outstanding references to it. When you save your context after deleting an object, you will remove the backing reference in the store. This means, your object has no actual record in the database. The next time you use that object, Core Data will yell at you.

2) Problem 1 occurs a lot when you have threaded background saves. A solution you can use is to refetch all our data object references after you save so you are guaranteed to have correct data and valid objects. MagicalRecord provides a completion block mechanism to help you out with this.

If you're suspecting your ManagedObjectModel as the problem, I have also had to do a clean build AND remove the app from the simulator/device to remove any previous build artifacts.

Upvotes: 1

Related Questions