Hi,

I had a problem this morning, and I am wondering if the behavior I've observed was normal or not.

I needed to use KVO on some object and wasn't able to figure why this didn't work. I spent some time figuring out what was happening (since it was the first time I used KVO, I started to blame my code). Reducing the problem, I finally found that my code didn't work because my observer was a subclass CALayer.

I attached the code that doesn't work (the observer method is not called).

If I make it a subclass of NSObject, it works. Is this a correct behavior or a bug ?

@interface Application : CALayer {
        NSString *manager;
}

@property (retain) NSString *manager;

@end

@implementation Application

@synthesize manager;

- (id) init
{
        self = [super init];
        if (self != nil) {
                [self addObserver:self forKeyPath:@"manager" options:0 
context:NULL];
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(fired:) userInfo:nil repeats:NO];
        }
        return self;
}

-(void)fired:(id)sender
{
        [self setManager:@"foo"];
        [self setManager:nil];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change
                                           context:(void *)context
{
        NSLog(@"Observed: %@ = %@", keyPath, [self manager]);
}       

@end

_______________________________________________

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 arch...@mail-archive.com

Reply via email to