• 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
Core Data design question: receiving KVO notifications of partially mutated objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data design question: receiving KVO notifications of partially mutated objects


  • Subject: Core Data design question: receiving KVO notifications of partially mutated objects
  • From: "Sean McBride" <email@hidden>
  • Date: Fri, 30 Oct 2009 18:01:48 -0400
  • Organization: Rogue Research Inc.

Hi all,

What is considered best practice when it comes to mutating many
properties of a managed object, specifically with regard to KVO
observers getting notified before all mutations are finished?

Let's say I have an Rectangle object.  It has properties: colour, width,
height.  Imagine some controller observing all these properties, perhaps
to trigger a redraw.

If I do:

 [rect setColour:...];
 [rect setWidth:...];
 [rect setHeight:...];

This is short and readable.  But observers will be notified after each
setter.  This could be a problem if intermediate states are not self-
consistent and could also lead to unnecessary redrawing.  In the general
case, I might not even know who is observing.

I guess it's safer to create a setColour:width:height: method in my
NSManagedObject subclass that does:

	[self willAccessValueForKey:@"colour"];
	[self willAccessValueForKey:@"width"];

	[self setPrimitiveColour:...];
	[self setPrimitiveWidth:...];

	[self didAccessValueForKey:@"width"];
	[self didAccessValueForKey:@"colour"];

Is this what I should be doing?

I can see it getting ugly with more than 3 or so properties...

Thanks,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

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: Core Data design question: receiving KVO notifications of partially mutated objects
      • From: Graham Cox <email@hidden>
    • Re: Core Data design question: receiving KVO notifications of partially mutated objects
      • From: Kiel Gillard <email@hidden>
  • Prev by Date: Re: making the NSScrollView align its subview to the top-left corner
  • Next by Date: Re: Scripting Bridge running method passing an array
  • Previous by thread: Re: making the NSScrollView align its subview to the top-left corner
  • Next by thread: Re: Core Data design question: receiving KVO notifications of partially mutated objects
  • Index(es):
    • Date
    • Thread