• 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: Jerry Krinock <email@hidden>
  • Date: Wed, 25 Feb 2009 18:08:32 -0800


On 2009 Feb 25, at 17:11, Ben Trumbull wrote:

bug numbers ?

Ben, I will definitely file bug(s) after I get this sorted out. But in the interim...


The problem is easily stated in terms of DepartmentAndEmployees. I have views which want to know when various object properties change. For one example, say I want to add an OrgChart object. My OrgChart wants to receive a notification or observation when the directReports of any Employee is changed.

There appear to be solutions to this problem and both are surprisingly complicated.

Solution 1. Use KVO. Although adding observers is systematic (awakeFromInsert + awakeFromFetch), removing observers must be done (1) when deallocating the moc and (2) in the managed object's -dealloc method (which is not recommended for subclassing). The latter is to catch objects still on the undo stack or elsewhere.

Solution 2. Use Custom Setters. In each setter, post a notification. This is not too bad with attributes -- only one setter per attribute. But for to-many relations you need to override the four, or is it five, set mutator methods, and what if more are added in some future version of Mac OS? This requires much code and seems fragile.

Which solution, or a different one, looks "better" to you?

Thank you,

Jerry
_______________________________________________

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


References: 
 >re: Observing Managed Object Changes. Was: Strange ... behavior (From: Ben Trumbull <email@hidden>)

  • Prev by Date: Re: do i need to create autorelease pool?
  • Next by Date: One IBAction, multiple results from multiple methods
  • Previous by thread: re: Observing Managed Object Changes. Was: Strange ... behavior
  • Next by thread: One IBAction, multiple results from multiple methods
  • Index(es):
    • Date
    • Thread