order of KVO notification
order of KVO notification
- Subject: order of KVO notification
- From: Jeff Gilbert <email@hidden>
- Date: Mon, 26 Mar 2007 18:20:31 -0500
Hi Everybody,
Is there a defined order that KVO notifications are posted to observers?
For example, let's say I have a collection of objects (e.g. Foo) with
a price attribute. I have another object (PriceValidator) that
observes, via KVO, the price of all the Foos so that it can maintain
a cache of values related to the price. So, if one Foo changes its
price, PriceValidator will flush its cache. The PriceValidator
registers for KVO on Foo price when the document is created.
I have a window that processes the Foo objects and uses KVO to
observe the price of the Foos. If a price changes, the window
retrieves a value from the PriceValidator. The window registers for
KVO on Foo price when the window is opened (via a user command--this
is not the default document window). This will always happen after
the PriceValidator has register for KVO.
Now, the problem is that the window will be notified of the price
change before the PriceValidator is notified of the price change. So,
when the window retrieves a value from the PriceValidator it is an
old value. I need the PriceValidator to be notified first so that it
can clear its cache. Then, when the window retrieves the value from
the PriceValidator it will recompute the new value.
I was thinking that the PriceValidator would be notified first since
it was registered first. This does not seem to be the case. Is it
reasonable to expect this behavior? Is there any way to cause this
behavior? If not, can anyone recommend a useful workaround for this?
thanks,
Jeff Gilbert
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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