Re: How to keep creation/modification date of a (Core Data) object?
Re: How to keep creation/modification date of a (Core Data) object?
- Subject: Re: How to keep creation/modification date of a (Core Data) object?
- From: "Arthur C." <email@hidden>
- Date: Tue, 17 Jul 2007 21:06:58 +0200
You should go back and (re)read Ben's post.
Okay, thanks. I missed that thread, which runs parallel to mine. For
completeness, the link:
<http://www.cocoabuilder.com/archive/message/cocoa/2007/7/15/186219>
-didChangeValueForKey: is going to be sent anytime a key changes in pointer
equality. This includes firing faults and undo. In neither case should the
modification date be bumped.
More specific, the modification date has to return to its old value whenever
a change is undone (well, you could argue about that, but at least that
would be compatible with Apple's choice. When you edit a text file in
TextEdit, and undo the changes, the file is clean again, i.e. does not have
to be saved).
To include correct behaviour on undo, the code is updated as follows:
- (void) didChangeValueForKey: (NSString *) thisKey
{
[super didChangeValueForKey: thisKey];
if( ( [thisKey isEqualToString:@"modificationDate"] == NO) && ([self
isFault] == NO) && ([[[self managedObjectContext] undoManager] isUndoing] ==
NO) && (startUpFinished == YES))
{
[self setModificationDate: [NSDate date]];
}
}
Using [self setPrimitiveValue:[NSDate date] forKey:@"modificationDate"]; as
suggested by Ben, does not give correct behaviour, as the modification date
is not updated on screen (no will/did change notifications, so the binding
is not triggered...).
The [self isFault] condition will not help me get rid of the startUpFinished
flag.
I'm currently using the most precise and most inconvenient method of
maintaining the modification dates.
Putting a setModificationDate call in every setter, yes... but that was the
reason I started this thread, to find a solution with less / better code.
It's surprisingly hard to implement this (obvious) feature in a 'convenient'
way...
Best regards,
Arthur C.
Jim
_________________________________________________________________
FREE pop-up blocking with the new Windows Live Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden