5

I am asking for an Value like this:

[self.layer valueForKeyPath:@"transform.rotation.z"]

bit I need to pass it to a method which takes a CGFloat as parameter. What's the casting trick here?

Thanks
  • 39,609
  • 71
  • 204
  • 317

2 Answers2

19

In Swift:

let f = view.layer.valueForKeyPath("transform.rotation.z")!.floatValue

In Objective-C:

NSNumber* n = [self.layer valueForKeyPath:@"transform.rotation.z"];
CGFloat f = [n floatValue];
Rhythmic Fistman
  • 33,182
  • 5
  • 81
  • 149
1

If you wanted a more concise, one line way to do that, you can do:

CGFloat f = [[self.layer valueForKeyPath:@"transform.rotation.z"] floatValue];
Neil
  • 1,783
  • 1
  • 11
  • 20