Thanks, that's good to know. But it doesn't solve my particular problem. I'm
now calling the super class as described, but it doesn't help.
int foo;
int *bar = &foo;
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
NSLog(@"oVFKP: %@", keyPath);
if (context == bar) {
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change
context:context];
}
}
--- On Wed, 10/15/08, Jim Correia <[EMAIL PROTECTED]> wrote:
> From: Jim Correia <[EMAIL PROTECTED]>
> Subject: Re: tearing my hair out: +(NSSet
> *)keyPathsForValuesAffectingValueForKey:
> To: [EMAIL PROTECTED]
> Cc: "Cocoa Developers" <[email protected]>
> Date: Wednesday, October 15, 2008, 5:54 PM
> 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 ([email protected])
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]