#42: UIColor and CGFloat
Question
// Swift Quiz
— objc.io (@objcio) January 29, 2020
// by @tammofreese
import UIKit
let color1 = UIColor(white: 1 / 255, alpha: 1.0)
let color2 = UIColor(white: 1.0 / 255.0, alpha: 1.0)
let result = (color1 == color2)
// What‘s the value of result?
Solution
Solution: true
— objc.io (@objcio) January 30, 2020
Because this initializer of UIColor takes a CGFloat, the expression 1 / 255 gets typed as a CGFloat expression, and will have the same value as 1.0 / 255.https://t.co/s7500CWmAg