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: Jim Correia <email@hidden>
- Date: Sun, 15 Jul 2007 15:26:52 -0400
On Jul 15, 2007, at 3:17 PM, Arthur C. wrote:
I have found the following solution (thanks to your replies), which
makes use of an override of the didChangeValueForKey method.
@implementation myManagedObject
- (void) didChangeValueForKey: (NSString *) thisKey
{
[super didChangeValueForKey: thisKey];
if ( ([thisKey isEqualToString: @"modificationDate"] == NO) &&
( [self finishedStartup] == YES ) )
{
[self setModificationDate: [NSDate date]];
}
}
Now that looks simple... However the small complication is that the
modification date is also set when the program starts, as it calls
the setters of the object to recreate the values it had before.
You should go back and (re)read Ben's post.
-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.
I'm currently using the most precise and most inconvenient method of
maintaining the modification dates. (In part, because not all key
changes should result in the logical change of the modification date
- some are meta-values. YMMV.)
Jim
_______________________________________________
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