On Sep 25, 2011, at 11:13 PM, Jerry Krinock wrote:

> I'm debugging a corner case wherein undoing a group containing deletion of a 
> managed object causes a "Core Data could not fulfill a fault" exception on 
> this object.  It would help to understand exactly how managed objects are 
> un-deleted.
> 
> If I delete a managed object, and then save (or if Cocoa autosaves in place) 
> the object is turned into a fault.  Normally, Undo is still able to restore 
> the object.  As implied by the documentation [1], the restored object is the 
> same object; it has the same address as the original.
> 
> My guess is that the undo invocation contains dictionaries of deleted object 
> properties which are used during Undo to re-populate the properties of a 
> faulted object.  Is that indeed the way it works?  (Feel free to improve my 
> wording.)
> 
> Any ideas how I could be hosing those properties, other than by 
> over-releasing the object?

My rough testing of a managed object (no undo grouping) produced the following 
results.

If I delete a managed object it is immediately turned into a fault.

The managed object I get back from undo has the same address as the original.

The managed object is not deallocated until the managed object context is 
rolled back or the document is closed.

Monitoring a few methods in a document based core data application produces a 
trace something like this.

1. Create managed object:
         [NSManagedObject alloc]
         [NSManagedObject awakeFromInsert]

2. Delete managed object: 
         [NSManagedObject willTurnIntoFault]
         [NSManagedObject didTurnIntoFault]

3. Save document:
          nothing

4. Undo deleted managed object:
          nothing

5. Delete managed object again: 
         [NSManagedObject willTurnIntoFault]
         [NSManagedObject didTurnIntoFault]

6a. Rollback managed object context:
         [NSManagedObjectContext rollback];
         [NSManagedObject dealloc];

6b. Or close the document:
         [NSManagedObject dealloc];

Regarding the contents of the undo and redo stack you could inspect it's 
contents using something like this.

     http://parmanoir.com/Inspecting_NSUndoManager's_undo_stack

Hope this helps.

--Richard

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to