• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is KVO really as complicated as I think?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 17:24:56 -0400

On 27 Apr 2004, at 14:57, mmalcolm crawford wrote:
On Apr 27, 2004, at 10:44 AM, Steve Sims wrote:

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.

You should still be able to set up relevant dependencies?
If you want to avoid recalculation then null out {e,f,g} when the values on which they depend change (i.e. in relevant set accessors of {a,b,c,d}) and recalculate and cache when the value is null?

OK, I think I'm starting to understand this better, and it looks like I want KVO to be a bit nicer than it is.

mmalc, your idea seems fairly sound and should work, so thanks for the suggestion. However I have a lot of UI elements that affect the derived parts of my data model, so this idea would seem to mean that I'd need to write a whole load of setters to do the nulling thing. In fact I may as well not bother with nulling but just do the recalculation. I'd hoped to be able to do without a big mess of setters and accessors by using bindings and KVO.

So having thought about this more, and read a whole load more, it seems that what I should really be doing is using addObserver:, and also implementing an observeValueForKeyPath: call. This way in my observeValueForKeyPath: routine I can check for changes to the key values that my derived values depend upon, and force updates to my derived values when appropriate. No setters of accessors necessary.

What I don't like about this is it does not seem like a particularly elegant way to do things - having to use string comparisons seems inefficient. My observeValueForKeyPath: routine is also likely to get very complicated... However from what I can see it should work.

One minor problem though is I can't find any code beyond Apple's tiny example in their documentation that uses this technique. If anybody can point me towards some other code that uses this technique I'd be a very happy chap.

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.


  • Follow-Ups:
    • Re: Is KVO really as complicated as I think?
      • From: mmalcolm crawford <email@hidden>
    • Re: Is KVO really as complicated as I think?
      • From: mmalcolm crawford <email@hidden>
References: 
 >Is KVO really as complicated as I think? (From: Steve Sims <email@hidden>)
 >Re: Is KVO really as complicated as I think? (From: Óscar Morales Vivó <email@hidden>)
 >Re: Is KVO really as complicated as I think? (From: Steve Sims <email@hidden>)
 >Re: Is KVO really as complicated as I think? (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: RE: [Q] am I allowed to call NSTableDataSource informal protocol methods myself?
  • Next by Date: Re: Is KVO really as complicated as I think?
  • Previous by thread: Re: Is KVO really as complicated as I think?
  • Next by thread: Re: Is KVO really as complicated as I think?
  • Index(es):
    • Date
    • Thread