Re: KVO, design and documentaion
Re: KVO, design and documentaion
- Subject: Re: KVO, design and documentaion
- From: Scott Stevenson <email@hidden>
- Date: Fri, 26 Jan 2007 18:55:41 -0800
On Jan 25, 2007, at 1:44 PM, patrick machielse wrote:
Notice also that I used:
[object addObserver:self forKeyPath:@"test" options:0 context:NULL];
I'm passing 0 for options:, because I'm not interested in either
the new or the old value of the 'test' property. *NOWHERE* in the
documentation does it say that this is allowed or even works.
Just some thoughts on all of this, do with them as you will --
Using nil or NULL for options is pretty typical throughout Cocoa. I
don't know for sure if it's documented, but it's certainly common in
code.
The crash and double observer issues are interesting, and certainly
worth filing bugs about. No one claimed the frameworks are
perfect. :) They're software, just like apps. If you work with
something enough, you're likely to encounter a case that a developer
didn't consider or made a mistake on. I don't think either are a good
enough reason to not use KVO, for whatever that's worth.
In any case, KVO is not meant to be a complete replacement for
NSNotification. KVO is specifically designed for key-value changes,
whereas NSNotification is more for general state change. Maybe that's
obvious, I don't know.
Also, I believe KVO has zero cost for publishing a notification when
there are zero observers, unlike NSNotification which always has some
cost, even if no one is listening (if a tree falls in the forest...).
I believe I've seen examples of KVO being considerably more scalable
in general, though that was years ago so things may have changed.
Reporting bugs here is good so that people can find them by searching
the archives, but the only real way to get anything fixed is via the
bug reporter:
http://bugreport.apple.com/
- Scott
_______________________________________________
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