• 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: KVO one-step listening but two-step notifying?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO one-step listening but two-step notifying?


  • Subject: Re: KVO one-step listening but two-step notifying?
  • From: mmalcolm crawford <email@hidden>
  • Date: Fri, 23 Dec 2005 01:21:00 -0800


On Dec 22, 2005, at 9:56 PM, Daniel Jalkut wrote:

Hmm - I'm confused. What's the distinction between:

1. It's OK to to invoke will/didChange without a change actually happening (just inefficient).
2. Not alright to invoke *both* after a change has occurred (to tickle).


1: (OK)

key = "a"; // no change
willChangeValueForKey:@"key";
didChangeValueForKey:@"key";

2: (Not OK)

key = "a";
// ...
key = "b"; // change
willChangeValueForKey:@"key";
didChangeValueForKey:@"key";

I'm assuming that *both* in the second essentially means "will/ didChange". If it's OK to do when nothing has happened, how can it be wrong (dangerous, not just inefficient) to do so some time after a change has already occurred? Isn't that the same (safety-wise) as "nothing has happened"?

No, because a change has actually happened in the second case, and the KVO machinery may need the old value to calculate a delta. Some parts of bindings *require* the old and new values...
(See <http://developer.apple.com/documentation/Cocoa/Reference/ Foundation/ObjC_classic/Protocols/NSKeyValueObserving.html#// apple_ref/doc/c_ref/NSKeyValueChangeKindKey>.)

(KVO can cope with the old and new values being the same. It'll just take a few more cycles than not invoking the methods at all...)

mmalc

_______________________________________________
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
  • Follow-Ups:
    • Re: KVO one-step listening but two-step notifying?
      • From: Daniel Jalkut <email@hidden>
References: 
 >KVO one-step listening but two-step notifying? (From: Hamish Allan <email@hidden>)
 >Re: KVO one-step listening but two-step notifying? (From: mmalcolm crawford <email@hidden>)
 >Re: KVO one-step listening but two-step notifying? (From: Daniel Jalkut <email@hidden>)
 >Re: KVO one-step listening but two-step notifying? (From: mmalcolm crawford <email@hidden>)
 >Re: KVO one-step listening but two-step notifying? (From: Daniel Jalkut <email@hidden>)

  • Prev by Date: Re: R: Running out of VM
  • Next by Date: Re: KVO one-step listening but two-step notifying?
  • Previous by thread: Re: KVO one-step listening but two-step notifying?
  • Next by thread: Re: KVO one-step listening but two-step notifying?
  • Index(es):
    • Date
    • Thread