Re: Compiler does not synthesize KVO compliant properties for CATiledLayer subclass (was: Synthesized properties for scalars not KVO compliant)
Re: Compiler does not synthesize KVO compliant properties for CATiledLayer subclass (was: Synthesized properties for scalars not KVO compliant)
- Subject: Re: Compiler does not synthesize KVO compliant properties for CATiledLayer subclass (was: Synthesized properties for scalars not KVO compliant)
- From: Kiel Gillard <email@hidden>
- Date: Fri, 22 May 2009 16:49:20 +1000
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 (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