Core Data design question: receiving KVO notifications of partially mutated objects
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