views:

129

answers:

1

I have a CoreData-driven navigation app and I'm trying to figure out why It's crashing.

I've got a hierarchy which is 3 view Controllers deep, all related by coredata relatioships, like this.

TableViewA =relationship= TableViewB =relationship= TableViewC

I'm honestly a novice at core data and I think my problem lies in the fetched results controller. I have one in TableViewA and another in TableViewB, and no matter how deep I go, the console always cites TableViewB's fetched results controller methods after a crash. Is this the problem?

What's happening specifically is if I launch my app and drill down into the hierarchy of one record, let's call it Record1, I can delete sub records to my hearts content. Gone! no problem!

But the second I go back to TableViewA and drill down into a different record, let's call that one Record2, and try to delete it's subrecords my app crashes, with the console citing this code from TableViewB as the problem.

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { // The fetch controller is about to start sending change notifications, so prepare the table view for updates. [self.tableView beginUpdates]; }

When I go into the debugger, the specific method it always has a problem with is:

if (![x.managedObjectContext save:&error]) {

 NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
 abort();
}

Just a confirmation of my idiocy with CoreData is all I'm looking for I think. Oh and how many ManagedObjectContexts should I have in an app of this type. I've been told I should have separate ones for adding content, which then should re-integrate into the main one. Is this true? Thanks!

A: 

I feel like this is a problem where you delete subrecords for Record1, then some inconsistency occurs when you go to delete the subrecords for Record2 - the original managed object context doesn't get saved, or gets into a conflict, or some such. I'd definitely check into your Core Data object management before your table view code.

As for having multiple managed object contexts, usually you only have an additional context when you're adding entirely new records. The typical pattern is to add new records into a secondary context, then merge that context into your app's primary context once the new record is added and saved. For modification or deletion, just use the original context.

I could be more definite about the problem you're having if you post the logging output of the NSLog statement in your last code snippet. The error's domain, code, and userInfo attributes will all be tremendously helpful here.

Tim