You can use "==" or isEqual. I just checked both of them and they work great:
let redColor = UIColor.redColor() let greenColor = UIColor.greenColor() let blueColor = UIColor.blueColor() let testColor = UIColor.greenColor() println( testColor == redColor ) // false println( testColor == greenColor ) // true println( testColor == blueColor ) // false println( testColor.isEqual(redColor) ) // false println( testColor.isEqual(greenColor) ) // true println( testColor.isEqual(blueColor) ) // false
I just reproduced the problem only after highlighting the SKSpriteNode color and, as you said, only with the colors of the fractions. You can solve this problem by comparing the color description as follows:
let blue_color = UIColor(red: 122/255, green: 180/255, blue: 190/255, alpha: 1) let yellow_color = UIColor(red: 253/255, green: 213/255, blue: 123/255, alpha: 1) let red_color = UIColor(red: 238/255, green: 116/255, blue: 71/255, alpha: 1) func randomColorController() -> UIColor { let random = arc4random_uniform(3) + 1 switch random { case 1: return blue_color case 2: return red_color case 3: return yellow_color default: return UIColor.clearColor() } } let square = SKSpriteNode(color: randomColorController(), size: CGSize(width: 30, height: 30)) if square.color.description == blue_color.description { println(true) } if square.color.description == red_color.description { println(true) } if square.color.description == yellow_color.description { println(true) }
source share