making a key depend on keypaths of self
making a key depend on keypaths of self
- Subject: making a key depend on keypaths of self
- From: Phil Frost <email@hidden>
- Date: Tue, 15 Nov 2005 15:09:38 -0500
Let's say I have a have some hierarchy of things, each of which has a
price. For the leaf nodes the price is a simple value, but for the
nonleaf nodes the price is the sum of its subthings. I would like to
have 'price' send change notices when subthings are added or removed, or
the price of a subthing changes.
The first solution that came to mind was to bind "price" to
"email@hidden". While I can get the value of
"email@hidden", when I try to bind I get:
[<NSCFSet 0x696f790> addObserver:forKeyPath:options:context:] is not supported. Key path: @sum.priceEach
So, although sets forward requests for keys to their members and return
a useful result, they don't support observing those, which is a bummer.
I tried to implement this functionality. I figured I could start
observing things when they are added to the set, and unobserve them when
they leave, and based on that be able to send notifications as needed.
The problem then is that I don't know how I'd send notifications. From
what I can tell the only way is to call will/didChangeValueForKey: and
friends, but firstly I could never call willChange... before making the
change since I don't receieve notification until after it has happened,
and secondly these methods work only for keys, and not keypaths.
Can anyone suggest an alternate solution, or some interface that might
help me here?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden