TIL two instances of `UIColor` can't be directly compared
Spend half of a day explaining to colleague that callbacks are not always better then delegate. As a result created this gist.
Two instances of UIColor
can’t be directly compared. Color space should be considered.
CGColorEqualToColor clearly says:
Two colors are equal if they share the same color space and numerically equal color components.
let blackColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
blackColor.isEqual(UIColor.black) // false
Another thing I have learned that func getRed(_ red:, green:, blue:, alpha:) -> Bool
may not return color components if color isn’t compatible with RGB.
Probably, it’s time revise habit that color is on 0…1 range.
On applications linked for iOS 10 or later, the red/green/blue component is specified in an extended range sRGB color space and can have any value. Values between 0.0 and 1.0 are inside the sRGB color gamut. On earlier versions of iOS, the specified value is always between 0.0 and 1.0.