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: Dave Keck <email@hidden>
- Date: Thu, 21 May 2009 20:12:09 -1000
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. 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];
}
(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
_______________________________________________
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