views:

49

answers:

1

Hi,

How different is the behavior of CALayer's valueForKey from that of any other ordinary NSObject's?
I have a custom layer which inherits from CALayer, and that has a property named 'angle', but [myLayer valueForKey: @"angle"] always returns nil while [myLayer angle] returns the right value.

ValueForKey: works as intended with a class inherited from NSObject, but not one from CALayer, so I guess it's [CALayer valueForKey:] that's doing some strange tricks..

Thanks!

+1  A: 

The whole Core Animation is actually backed by C++ code, the interface is just an Objective-C wrapper. Therefore, functions like -valueForKey: has been reimplemented to go through the C++ core first. This is the difference from NSObject.

If your -angle is just a method, not a declared property, the custom -valueForKey: won't find it. This is likely a bug. Try to make sure you declare a property .angle.

@property(assign) float angle;
KennyTM
Excellent! Thanks for the prompt and insightful answer! Just out of curiosity, where do you get information like this? Because I often find that Cocoa documents are not just enough. Do you work for Apple? ;)
Kay
I wanted to vote this up, but I don't have enough reputation..
Kay
I've posted a further question in relation to this one. Can you take a look if you have time? Thank you!http://stackoverflow.com/questions/3170723/animation-a-custom-calayer-property
Kay