2

edited with extra information: I am using an app based on CoreDataTableViewController from cs193p. When I delete an instance of an entity called Position, the prepareForDeletion is called immediately. But when I call saveToURL, or when the database is being autosaved, prepareForDeletion is called again.

Is this the way it should be? can I prevent it?

litov
  • 540
  • 5
  • 16

2 Answers2

0

Set a BOOL isDeleting and check to see if the process is already being ran.

Example

- (void) prepareForDeletion
{
    if ( isDeleting ) 
        return;


    /* handle the rest of the deleting process */
    isDeleting = YES;


    if ( /* the process has finished deleting */ )
        isDeleting = NO;
}
WrightsCS
  • 50,551
  • 22
  • 134
  • 186
  • this will not work. since the first prepareForDeletion is completed before the second one start. and it is also bypassing the problem, not really solving it I think – litov Jun 30 '12 at 06:52
0

It's probably the way it should be. UIManagedDocument uses two ManagedObjectContexts. When the child context (document.managedObjectContext) saves, it does so to its parent context. The objects in the parent context will in turn have their prepareForDeletion called immediately when the parent saves to the persistent store.

Andreas
  • 2,665
  • 2
  • 29
  • 38