0

Any suggestions how this code works in iOS 9 with xcode 7?

color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)

It says "Expected declaration"

Here is the code:

var red: CGFloat = 0.0
var green: CGFloat = 0.0
var blue: CGFloat = 0.0
var alpha: CGFloat = 0.0

color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
webLabel.text = String(format: "#%02X%02%02X", CInt(red*255),CInt(green*255),CInt(blue*255))

"color" is assigned previously like so:

var color: UIColor
{
    return UIColor(hue: CGFloat(hue/360), saturation: CGFloat(saturation/100), brightness: CGFloat(brightness/100), alpha: 1.0)
}

I have just started with the xcode 7 and swift so I am rookie at this. Thanks in advance.

Karl Kivi
  • 145
  • 11

1 Answers1

3

SWIFT 2.0 total solution

below is the total solution/Anwser for your question.Please be kind enough to make this answer as correct if it works.

func converUIColorToHex(colorToConver:UIColor)-> String{

    var red:CGFloat = 0
    var green:CGFloat = 0
    var blue:CGFloat = 0
    var alpha:CGFloat = 0

    colorToConver.getRed(&red, green: &green, blue: &blue, alpha: &alpha)

    print(red)

    if(red < 0) {red = 0}

    if(green < 0) {green = 0}

    if(blue < 0) {blue = 0}

    if(red > 255) {red = 255}

    if(green > 255) {green = 255}

    if(blue > 255) {blue = 255}

    print(red)

    let decimalCode = Int((red * 65536) + (green * 256) + blue)

    let hexColorCode = String(decimalCode, radix: 16)

    print(hexColorCode)

    return hexColorCode
}
Chamath Jeevan
  • 5,072
  • 1
  • 24
  • 27