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?
A CGFloat is a specialized form of Float that holds either 32-bits of data or 64-bits of data depending on the platform. The CG tells you it's part of Core Graphics, and it's found throughout UIKit, Core Graphics, Sprite Kit and many other iOS libraries.
As others have said, CGFloat is a float on 32-bit systems and a double on 64-bit systems.
In Objective-C, we generally use CGFloat for doing floating point operation, which is derived from basic type of float in case of 32-bit and double in case of 64-bit.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With