Hi Dave, On 22/05/2009, at 4:12 PM, Dave Keck wrote:
Hello, A few days ago I was having this same issue. The reason KVO doesn't work out-of-the-box with CALayer subclasses, I believe, is because CALayer overrides +automaticallyNotifiesObserversForKey: to return NO. My solution was to override +aNOFK: in my custom subclass to return YES for my custom key. This has worked flawlessly for me - please let me/us know whether it does for you.
Thanks! This seems to be a solution to the problem.
Here's the applicable code snippet: + (BOOL)automaticallyNotifiesObserversForKey: (NSString *)key { /* The NSObject implementation defaults to returning YES to this method. But because we're a CALayer subclass, we have to override it to return YES when key == one of our properties. This is because CALayer overrides the NSObject default functionality, so that this method always returns NO for CALayer and its subclasses. */ if ([key isEqualToString: @"gridShown"]) return YES; return [super automaticallyNotifiesObserversForKey: key]; }
It would be great if we could get a reason as to why it seems to always return NO. My guess would be that there could be a significant performance overhead using the KVO mechanism for every layer's property?
(I suppose we could figure out definitively whether CALayer was overriding +aNOFK: by comparing its +aNOFK: IMP with NSObject's +aNOFK: IMP. If I try this I'll get back to the list with my findings...) David
Thanks David, that'd be great! Kiel _______________________________________________ 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