I am trying to convert a Float value to CGFloat Value, here my code:
let myFloatForR = 0
let r = CGFloat(myFloatForR)
let myFloatForG = 0
let g = CGFloat(myFloatForG)
let myFloatForB = 0
let b = CGFloat(myFloatForB)
let myFloatForA = 0
let a = CGFloat(myFloatForA)
tintColor.getRed(r, green:&g, blue:&b, alpha:&a)
but suddenly the Xcode gives me a warning says: "Cannot convert value of type 'CGFloat' to expected argument type 'UnsafeMutablePointer" on the "tintColor" line? Anyone can help me?
You need to change the CGFloat
objects as var
instead of let
and pass pointer object for red value in getRed
method.
Updated Code
let myFloatForR = 0
var r = CGFloat(myFloatForR)
let myFloatForG = 0
var g = CGFloat(myFloatForG)
let myFloatForB = 0
var b = CGFloat(myFloatForB)
let myFloatForA = 0
var a = CGFloat(myFloatForA)
tintColor.getRed(&r, green:&g, blue:&b, alpha:&a)
OR
You can optimize your code after declaring r
, g
, b
and a
using single line of code.
var r: CGFloat = 0, g: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0
tintColor.getRed(&r, green:&g, blue:&b, alpha:&a)
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