2

So.. CALayer KVC "extensions" handle all the weirdo's... such as..

+ (id) defaultValueForKey: (NSString*)key    {
   return [key isEqualToString:@"borderColor"] 
        ? (id)cgPINK 
        : [super defaultValueForKey:key];    } 

And Apple's Docs allude to how best to encode a struct, when they refer to the default value if you DON'T provide a value...

For example, if the value for key is a CGSize struct, the method returns a size struct containing (0.0,0.0) wrapped in an NSValue object.

However, I can't figure out how to provide normal, stinking, primitives, i.e. CGFloat

I've tried @VAL-type NSNumber encoding,

return ![key isEqualToString:@"lineWidth"] ?: @3;

and with no viable NSValue methods, even a desperate attempt to cast them to id

return ![key isEqualToString:@"zPosition"] ?: (id)262453;// lol

What's the deal? Is this just an "oh-well, ya can't" situation due to CALayer's odd-ball nature? An obvious solution I have embarrassingly overlooked? Or is it just a shady API - that refuses to document it's own shortcomings?

Alex Gray
  • 16,007
  • 9
  • 96
  • 118

1 Answers1

0

You should be able to return an NSNumber.

I haven't yet tried using Objective C literals. Skip that for now to limit the complications. Just use code like this:

return [NSNumber numberWithFloat: 3.0];

or numberWithBool, or numberWithInt, or whatever is appropriate.

Duncan C
  • 128,072
  • 22
  • 173
  • 272