• 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: CoreData: Using willSave to update timestamps causes hang?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData: Using willSave to update timestamps causes hang?


  • Subject: Re: CoreData: Using willSave to update timestamps causes hang?
  • From: Jim Correia <email@hidden>
  • Date: Mon, 2 May 2005 12:53:39 -0400

On May 2, 2005, at 12:21 PM, mmalcolm crawford wrote:

On May 2, 2005, at 8:37 AM, Jim Correia wrote:

- (void)willSave
Invoked automatically by the Core Data framework when the receiver’s
managed object context is saved. It is commonly used to compute
persisted values from other transient values, to set timestamps, and so
on. This method can have “side effects” on the persistent values.
When I use this to do that exactly - modify the last saved timestamp of an object, I get a hang when saving. It appears that making the change inside of willSave causes willSave to be called again.
- (void)willSave
{
[self setValue: [NSDate date] forKey: @"lastSavedDate"];
}

- (void)willSave { [self setPrimitiveValue: [NSDate date] forKey: @"lastSavedDate"]; }

(Otherwise you're sending additional change notifications during the save process.)

Should the docs make that explicit? (If so, I'm happy to write a bug.)

If I do that in my willSave method, the last saved date in the UI doesn't update.

If I provide a didSave which does this

- (void)didSave
{
    [self willChangeValueForKey: @"lastSavedDate"];
    [self didChangeValueForKey: @"lastSavedDate"];
}

the UI updates, but I end up with a extra undo state that has no visible effect in the UI. (Perhaps it is undoing the lastSavedDate change, but the old value and the new are the same because of my hacked didSave method.)

What is the canonical way to update timestamps or values from didSave without ended up in a change loop and still having the values appear in the UI?

In particular in the case of time-stamps, since these are read-only from the UI perspective, the changes should be transparent and non- undoable by the user.

Thanks,
Jim _______________________________________________
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


  • Follow-Ups:
    • Re: CoreData: Using willSave to update timestamps causes hang?
      • From: mmalcolm crawford <email@hidden>
References: 
 >CoreData: Using willSave to update timestamps causes hang? (From: Jim Correia <email@hidden>)
 >Re: CoreData: Using willSave to update timestamps causes hang? (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: DocoaBrowser for 10.4?
  • Next by Date: Re: (freely) Rotating Text
  • Previous by thread: Re: CoreData: Using willSave to update timestamps causes hang?
  • Next by thread: Re: CoreData: Using willSave to update timestamps causes hang?
  • Index(es):
    • Date
    • Thread