Re: KVO, design and documentaion
Re: KVO, design and documentaion
- Subject: Re: KVO, design and documentaion
- From: Jim Correia <email@hidden>
- Date: Sat, 27 Jan 2007 16:53:58 -0500
On Jan 26, 2007, at 9:55 PM, Scott Stevenson wrote:
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.
It may be common, and the example in the documentation even uses
NULL, but it is certainly not recommended (by myself or others) for
KVO observers.
This was hashed out in the thread Matt pointed to. Here it is again
for reference:
<http://www.cocoabuilder.com/archive/message/cocoa/2006/7/14/167622>
You can get away with using NULL context pointer in well defined
situations (such as if your observer is a direct subclass of NSObject
and won't be subclassed itself), but you need to use a context
pointer in the class/subclass/superclass scenario if for no other
reason to determine if the message was really intended for you or not.
Yes, I've logged a bug against the documentation.
Jim
_______________________________________________
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