• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to keep creation/modification date of a (Core Data) object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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: Sun, 15 Jul 2007 21:17:22 +0200

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.
So I added a flag, BOOL finishedStartup; which must be set for the setModificationDate to be executed:


- (void) awakeFromFetch
{
  [self setFinishedStartup: YES];
}

The awakeFromFetch method gets executed after all the setters have been called, so that is the correct moment to set the flag.

The only problem remaining is that the compiler doesn't allow me to initialize the finishedStartup flag to NO (e.g. in the header file). As far as I know, ints and bools are automatically initialized to 0 (or NO), as long as they're not local variables in one of the methods. But of course it would be more prudent to do it yourself (by overriding the 'init' method?).

Anyway, thanks for the replies,

Arthur C.




Okay, but I have done that. Instance variable with setter and getter, and no typos. Does it matter that I'm adding a variable/key to a Core Data object? I don't want to include the extra variable (modificationDateChanged or something) in the data model, as I don't use it anywhere except for the triggerChangeNotification.


So why does the triggerChangeNotification have no effect? It just doesn't work.


Thanks again,

Arthur C.





On Jul 9, 2007, at 1:23 PM, Arthur C. wrote:


On 08/07/07, Arthur C. <email@hidden> wrote:
This must be a simple use of setKeys:
triggerChangeNofiticationsForDependentKey, but I can't find the right method
for the key 'modificationDate'...
Creation date is easy, just an awakeFromInsert will do.
But the modification date (obviously) has to change whenever any of the keys
in the object changes. Moreover, it has to keep its value when we are just
asking for the modification date (getter method), and on program
shutdown/restart.



_________________________________________________________________
Talk with your online friends with Messenger http://www.join.msn.com/messenger/overview



_________________________________________________________________ Hotmail en Messenger on the move http://www.msn.nl/services

_______________________________________________

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


  • Follow-Ups:
    • Re: How to keep creation/modification date of a (Core Data) object?
      • From: "Arthur C." <email@hidden>
    • Re: How to keep creation/modification date of a (Core Data) object?
      • From: Jim Correia <email@hidden>
References: 
 >Re: How to keep creation/modification date of a (Core Data) object? (From: "Arthur C." <email@hidden>)

  • Prev by Date: Re: NSApplicationMain options
  • Next by Date: Re: How to keep creation/modification date of a (Core Data) object?
  • Previous by thread: Re: How to keep creation/modification date of a (Core Data) object?
  • Next by thread: Re: How to keep creation/modification date of a (Core Data) object?
  • Index(es):
    • Date
    • Thread