• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
KVO and CALayers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

KVO and CALayers


  • Subject: KVO and CALayers
  • From: Yvan BARTHÉLEMY <email@hidden>
  • Date: Fri, 12 Dec 2008 15:39:38 +0100

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


  • Follow-Ups:
    • Re: KVO and CALayers
      • From: Matt Long <email@hidden>
  • Prev by Date: Re: Programmatically constructing list of variable arguments?
  • Next by Date: Re: Programmatically constructing list of variable arguments?
  • Previous by thread: Require help with Mouse click event on Status Item
  • Next by thread: Re: KVO and CALayers
  • Index(es):
    • Date
    • Thread