Message: 12
Date: Fri, 24 Feb 2006 11:19:53 -0600
From: Joshua Scott Emmons <email@hidden>
Subject: Re: Observing Undo in a Core Data App
To: Michael Clark <email@hidden>
Cc: Cocoa List <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
What do I observe to see if an item has been placed back into the
NSManagedObject context via Undo. Undo works: the most recently
deleted object is put back into the context - it's there when I
restart the application and reload the array. I just need to know
when an object is put back into the context so that I can update my
UI on the fly. Any suggestions on how to do this?
My solution to this was to crate a base managed object, "Office".
Office has a to-many relationship called "employees". My array
controller adds and deletes Employee managed objects from this to-
many relationship. Then, to recognize undo/redos, I just KVO Office's
"employees" relationship.
This was a quick fix when I did it. I didn't look for a better way,
and there very well might be one. But this worked well enough for me.
Oh, one more note. When proceessing the KVO with -
observeValueForKeyPath:ofObject:change:context:,
NSKeyValueChangeKindKey is NSKeyValueChangeRemoval on deletions and
NSKeyValueChangeInsertion on insertions. But as I recall it's NEITHER
on undos and redos. Just a heads up.
Cheers,
-Joshua Emmons