Re: Is KVO really as complicated as I think?
Re: Is KVO really as complicated as I think?
- Subject: Re: Is KVO really as complicated as I think?
- From: Steve Sims <email@hidden>
- Date: Tue, 27 Apr 2004 13:44:08 -0400
Oscar, thanks for the reply...
On 27 Apr 2004, at 12:31, Sscar Morales Vivs wrote:
Basically
setKeys:(NSArray*)theKeys
triggerChangeNotificationsForDependentKey:(NSString*)theKey;
Is your best friend. Works as advertised. Use it during initialization
(I'm putting those in the +initialize method of the model class). And
enjoy.
Now I had seen this, and it does seem to almost do what I want, but the
documentation is confusing me.
The problem is I've only seen this used in a simple setting, and the
derived data is only ever just returned and not stored. This is the
case in the Apple example code snippet they have
at:
http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueObserving/Concepts/DependentKeys.html
... as well as within their bindings-based currency converter example
found at:
http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaBindings/Tasks/ccwithbindings.html
As I indicated below I (potentially) want a cascade of value changes to
occur within my data model when a single value is changed, and there
are multiple cascade paths. Every example I have seen has no cascade
of changes - a or b changes, which results in observers of c being told
that c has changed. When an observer fetches c it gets programatically
created. Typically the observer of c is a view which displays it.
What I'm after is something a bit more complex. Lets say that my model
has UI elements which set values a, b, c and d. It also has derived
values e, f and g. There's an on-screen view which displays g. When
either a or b changes e should change. When c or e changes then f
should change. When d or f changes then g should change.
Put another way, e should get updated when either a or b changes, f
should update when either c or e changes, and g should update when
either d or f changes. What should not happen is e or f being
updated/recreated if c or d changes. These values should be stored,
since it would be inefficient and computationally expensive to create
them every time g is wanted.
Maybe I'm being dumb, but I can't see a sensible way to accomplish this
right now.
Any hints?
Steve
On 27 Apr 2004, at 12:00, Steve Sims wrote:
OK gang, so I've designed my UI, and have an underlying data model
designed too.
It seems to me that all the input elements of my UI can be hooked up
to my model fairly easily using bindings. This is very useful to me
since I have some dual-control elements where I've got text and
sliders referring to the same data.
My data model isn't entirely simple though. I have a number of
pieces of data that are derived from other bits of data in my model.
It seems to me that by observing changes made to the values within my
model that directly affect the derived elements I could potentially
automatically regenerate my derived data. Sometimes this would mean
that a UI event would change a single variable that would result in a
cascade of updates to derived data.
This would seem to be the kind of thing that bindings and KVO are
supposed to do. However the documentation is making my head spin
right now, and I haven't found any sample code that does anything
more complex than really basic bindings stuff - certainly nothing
where there's a cascade of changes within a data model.
In my ideal world the way I'd make this work is when I initialize my
object I would indicate that a particular selector should be called
when one of a particular set of values is changed. Oh, and I'd be
able to do this for multiple selectors and related data sets too.
Thus I'd be able to set things up so that my desired cascades of
changes would happen.
It seems that KVO almost does this, but not quite in the way that I
want it to, and right now I'm having trouble bending my brain around
the way that KVO does things. It seems that things the KVO way are
much more complex, and to get what I want I need an extra layer of
abstraction that's not built in.
I've tried searching around for sample code that demonstrates KVO, or
articles that better explain the concept, but I'm not coming up with
anything right now. Does anyone have any pointers?
Steve
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.