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
  • 40,109
  • 71
  • 208
  • 322

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
  • 34,352
  • 5
  • 87
  • 159
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,813
  • 1
  • 12
  • 20