Re: KVO and CALayers
Re: KVO and CALayers
- Subject: Re: KVO and CALayers
- From: Matt Long <email@hidden>
- Date: Fri, 12 Dec 2008 11:42:28 -0700
It would appear that you are right. I took your code and plugged it
into an xcode project and found that the manager property is not being
observed. I knew that you couldn't use KVO for animatable properties
in a CALayer, but it appears that CALayers don't allow KVO at all. As
soon as I made the object that you have named "Application" to be
NSObject derived, the -observeValueForKeyPath delegate started getting
called without a problem.
I think it's normal. It's not desirable, but I do think it is
intended. Maybe someone else will confirm or discount this, but I'm
thinking that the issue is KVO is an all or nothing kind of thing for
each class. You can't just disable it for a a certain set of
properties (animatable ones for instance). It's either enabled or it's
not. For a CALayer and derivatives, it appears that it's not.
Interesting problem.
Best regards.
-Matt
On Dec 12, 2008, at 7:39 AM, Yvan BARTHÉLEMY wrote:
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 (email@hidden)
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:
This email sent to email@hidden