• 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: Observing Managed Object Changes. Was: Strange ... behavior
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Observing Managed Object Changes. Was: Strange ... behavior


  • Subject: Re: Observing Managed Object Changes. Was: Strange ... behavior
  • From: Dave Fernandes <email@hidden>
  • Date: Wed, 25 Feb 2009 19:39:31 -0500


On Feb 25, 2009, at 8:31 AM, Jerry Krinock wrote:

So, it looks like, for observing changes to the properties of managed objects ---

* Using NSManagedObjectContextObjectsDidChangeNotification is no good
since it doesn't give you specific information on the current change
which actually caused the notification.


*  Using KVO is no good because observers must be removed before an
     object becomes a fault, and there is no mechanism to find out
     when the object un-becomes a fault, which you need to restore
     your observers.

So, my conclusion is that writing Custom Setters for any properties that need to be observed and posting a notification (coalesced, for efficiency) within the custom setter is the only viable technique.

Does anyone have any better ideas?

Jerry

Well, as I mentioned I have stuck with KVO. I don't see why you need to remove observers when turning into a fault. You only need to remove observers before the object disappears. I have created my own NSManagedObject subclass as you have, and I have a
-removeSelfFromObserveredObjects method in that subclass that I call before deallocating the MOC. (Fetch all objects from MOC and call this method, if it exists.) ...it's not pretty, but it works.


Note that a fetch will not return deleted objects that might still be on the undo stack, so I also call removeSelfFromObserveredObjects from the managed object's dealloc method. (You will have to check that you do not call removeSelfFromObserveredObjects twice.) As I said, it's not pretty, but it works.

If anyone has a better way, I'd love to hear it!

Dave
_______________________________________________

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: Observing Managed Object Changes. Was: Strange ... behavior
      • From: Jerry Krinock <email@hidden>
References: 
 >Strange NSManagedObjectContextObjectsDidChangeNotification behavior (From: Karolis Ramanauskas <email@hidden>)
 >Re: Strange NSManagedObjectContextObjectsDidChangeNotification behavior (From: Jerry Krinock <email@hidden>)
 >Re: Strange NSManagedObjectContextObjectsDidChangeNotification behavior (From: Dave Fernandes <email@hidden>)
 >Observing Managed Object Changes. Was: Strange ... behavior (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Observing Managed Object Changes. Was: Strange ... behavior
  • Next by Date: Re: Observing Managed Object Changes. Was: Strange ... behavior
  • Previous by thread: Re: Observing Managed Object Changes. Was: Strange ... behavior
  • Next by thread: Re: Observing Managed Object Changes. Was: Strange ... behavior
  • Index(es):
    • Date
    • Thread