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 protected]
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]