• 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: Modified date in CoreData model
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modified date in CoreData model


  • Subject: Re: Modified date in CoreData model
  • From: Ben Trumbull <email@hidden>
  • Date: Sat, 14 Jul 2007 15:17:48 -0700

On 7/13/07, Aaron Wallis <email@hidden> wrote:
 Hi all.

 I'm stuck in a bit of an infinite loop here guys,
 I need to set a *modified date* value for a CoreData model i'm
 building. I've been using the following peice of code, but for
 obvious reasons, it causes an infinite loop.

 - ( void ) didChangeValueForKey : ( NSString * ) key
 {
         [self setValue:[NSDate date] forKey:@"modifiedDate"];
 }

how would I go about doing such a thing?


As mentioned, you should use

[self setPrimitiveValue:[NSDate date] forKey:@"modifiedDate"];

However, you really should not change the objects in -didChangeValueForKey: like this. Key Value Observing requires notifications be sent any time a property value changes *pointer* equality, which includes undo, refresh, and faulting.

Updating the modified date because you rolled back via undo to a previous state, or you refreshed the object with newer data (from changes by another thread/process) is usually wrong.

You can change this in response to the -willSave callback when the context saves the changed object. You can change this in response to the context's NSManagedObjectContextObjectsDidChangeNotification which happens at the end of the user event, or when you call -processPendingChanges. Or for the most precision (and most inconvenience) you can add this line to every public setter.
--


terminally curious,

-Ben

__________________________________________________________________________
Ben Trumbull
email@hidden                            Development Technologies
(408) 974-5790                                       Core Data
Change is the Epitome of Hope.                  Apple Computer, Inc.
_______________________________________________

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


  • Prev by Date: NSApplicationMain options
  • Next by Date: [ANN] UKSoundFileRecorder
  • Previous by thread: Re: Modified date in CoreData model
  • Next by thread: Software Update APi in Cocoa
  • Index(es):
    • Date
    • Thread