• 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 - re-faulting object and removing self-observers results in messages being sent to zombie
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData - re-faulting object and removing self-observers results in messages being sent to zombie


  • Subject: Re: CoreData - re-faulting object and removing self-observers results in messages being sent to zombie
  • From: Bill Bumgarner <email@hidden>
  • Date: Tue, 2 Aug 2005 17:30:52 -0700


On Aug 2, 2005, at 1:55 PM, Jim Correia wrote:
I have a CoreData based application. One of my NSManagedObject subclasses observes itself (for a variety of reasons, but just this in on the example) so it can keep a lastModified time for each object.

Generally, observation of self is discouraged [though it should work, I think]. In any case, you are going to end up with a boatload of observers and lots of cycles spent maintaining the observers as managed objects are created and destroyed. And there are some issues in relation to faults, as you have discovered.


Instead, why not make the lastModifiedTime a dependent key on the rest of the object's keys?

In particular:

- make lastModifiedTime dependent upon all keys that need to update the lastModifiedTime

- override willChangeValueForKey: to:

- call super first
- check to see if the key is lastModifiedTime
- if it is, then use primitive KVC to set the lastModifiedTime to now


The above should work.  At least, Ben and I think it will work.

There are some subtle details to this. It works because the dependent invocation of willChangeValueForKey: for the lastModifiedTime key does not actually indicate that a new value is about to be set. Even when it is invoked in the case where traditional KVC is about to change that key directly, the value set in the implementation of willChangeValueForKey: (as described above) will be correctly lost -- will not appear in either the undo stack (because the super invocation of willChangeValueForKey: has already recorded the snapshot) or the object (because the set will happen after the willChange...:).

Alternatively, you could punt on the dependent key stuff and just make willChangeValueForKey: always update the lastModifiedTime, regardless of key (via the primitive KVC as described above).

Unfortunately, there isn't a "hey -- if that key changes, independently recompute the value of this key" hook. There probably should be. Someone should file a feature request, if they agree.

b.bum
_______________________________________________
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 - re-faulting object and removing self-observers results in messages being sent to zombie
      • From: Jim Correia <email@hidden>
    • Re: CoreData - re-faulting object and removing self-observers results in messages being sent to zombie
      • From: Jim Correia <email@hidden>
References: 
 >CoreData - re-faulting object and removing self-observers results in messages being sent to zombie (From: Jim Correia <email@hidden>)

  • Prev by Date: Re: RESEND: NSMetadataItem performance issues
  • Next by Date: Re: NSSegmentedControl Highlights
  • Previous by thread: CoreData - re-faulting object and removing self-observers results in messages being sent to zombie
  • Next by thread: Re: CoreData - re-faulting object and removing self-observers results in messages being sent to zombie
  • Index(es):
    • Date
    • Thread