Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why when converting Float to CGFloat Xcode give me a warning "Cannot convert value of type 'CGFloat' to expected argument type 'UnsafeMutablePointer"?

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?

like image 989
hdjkshdak Avatar asked Oct 26 '15 17:10

hdjkshdak


1 Answers

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)   
like image 118
deoKasuhal Avatar answered Nov 14 '22 17:11

deoKasuhal