Re: CoreData: Using willSave to update timestamps causes hang?
Re: CoreData: Using willSave to update timestamps causes hang?
- Subject: Re: CoreData: Using willSave to update timestamps causes hang?
- From: Jesse Grosjean <email@hidden>
- Date: Fri, 3 Jun 2005 17:57:52 -0400
Was a good solution ever found for this? I'm running into a similar
problem using NSPersistentDocument, I would like the UI to
indicated if my managed objects are (edited) have unsaved changes.
This should happen automatically. In what circumstances does it not
occur?
I don't think I was clear enough. My goal is to have an interface
when items that have been edited but not yet saved are shown with a
darkened icon, for example in XCode the file icons are darkened when
they have been edited but not yet saved. I want to implement the same
thing using core data.
It's very simple to get this almost working, to do that I have
created this edited method in my NSManagedObject subclass:
- (BOOL)edited {
return [self isInserted] || [[self changedValues] count] > 0;
}
I can bind this to my edited checkbox (i'm using a checkbox to
indicated edited status for now instead of a darkened icon) and it
almost works, but the checkbox isn't always updated when it should be
since no KVC notifications are not being sent for the "edited" key.
But when I try to remedy this by calling the willChangeValueForKey:
and didChangeValueForKey: methods when the managed object context is
updated or saved I run into all sorts of problems. It seems like core
data is trying to manage the "edited" key even though I haven't
declared it anywhere in the core data object model.
You can find an example project here.
http://www.hogbaysoftware.com/CoreDataEdited.zip
Right now it's broken (will go into an infinite loop) when you try to
insert an object. If you comment out the willChangeValueForKey and
didChangeValueForKey method in MyDocument it will work, but the
interface won't update properly. Or you can temporarily disable undo
registration when calling the changeValueForKey methods, but that
creates other problems, after saving the document it seems like
managedObjectContextObjectsDidChange notfications stop getting sent.
So is there a better way to do what I'm trying to do. If not how do I
make core data ignore willChangeValueForKey and didChangeValueForKey
for certain keys and instead use NSObjects implementation of those
methods?
Jesse
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden