Re: Key Value Observing?
Re: Key Value Observing?
- Subject: Re: Key Value Observing?
- From: Steve Steinitz <email@hidden>
- Date: Wed, 12 Dec 2007 17:31:49 +1100
Hi mmalc
Thanks for your reply. I have a question, a confession and a comment.
On 11/12/07, mmalc crawford wrote:
[Summary: I have a key whose value is dependent on values of attributes in a related entity — how do I ensure it is kept up to date > as the attribute values are changes and as the relationship is > manipulated?]
See ...CoreData/Articles/cdFAQ.html#//apple_ref/doc/uid/TP40001802-DontLinkElementID_24
The description is a bit sparse but one can read between the
lines. Its not the most straightforward thing to set up but it
does seem to work.
One thing i'm not clear on:
The article says 'You must add and remove the parent as an
observer as child objects are added to and removed from the
relationship'. Inconvenient but fair enough. However, that
implies that when a parent is instantiated it needs to loop
through all its existing children and register to observe their
innards. If that is the case, wouldn't it give a performance
hit for any application, like mine, that load tens of thousands
of parent objects at startup.
Would that be correct?
Let me share an evil hack I've done while I await the answer to
those questions. I didn't set Sale up as an observer for the
LineItems at all -- reluctant to code and debug it and debug the
registering / unregistering in the absence of answers. Instead,
I just overrode
LineItem setQuantity and
LineItem setSalePrice
to call my brand new dummy
Sale setTotal
method which does nothing more than call didChange (Sale has no
total ivar/attribute and the calculation is done in Sale
total). Bingo. Maintenance and encapsulation aside, I'm out of
hot water with my client.
I'd like to mention that the article you (mmalc) referenced has
made me realize the performance improvements available by
calculating the Sale total, for example, only when something
causes it to change. I'm currently calculating it everytime
anyone asks for it. Time for some re-engineering and custom KVO?
Thanks again,
Steve
_______________________________________________
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