On Oct 15, 2008, at 8:46 PM, Chris Idou wrote:
I can't do that because my object inherits from NSObject, and
NSObject doesn't contain an implementation of
observeValueForKeyPath. So that gives a runtime error.
NSObject does have an implementation of -
observeValueForKeyPath:ofObject:change:context: which raises an
exception for all unknown contexts.
This has been discussed ad naseum on the list.
To properly use KVO you must use a unique context pointer, and
implement your observer method like this:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if (context == MY_CONTEXT) {
/* do my work here */
} else {
[super observeValueForKeyPath: keyPath ofObject: object change:
change context: context];
}
}
Implement it like that always, even when you are a direct subclass of
NSObject. (If you change your superclass, your implementation will
still be correct. Etc.)
Jim
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]