UIColor's getRed:green:blue:alpha should be color space agnostic

Originator:marksands07
Number:rdar://14199042 Date Originated:18-Jun-2013 08:47 PM
Status:Open Resolved:
Product:iPhone SDK Product Version:iOS 5.0
Classification:Enhancement Reproducible:Always
 
Summary:
UIColor's getRed:green:blue:alpha only works for UIDeviceRGBColorSpace but silently breaks for UIDeviceWhiteColorSpace colors.

This results in having to revert to the CoreGraphics function CGColorGetNumberOfComponents to check if 4 components are returned or 2, which adds branching and redundant condition checks.

Steps to Reproduce:
Create a method that accepts a UIColor as an argument. Attempt to break apart the RGB color components by using UIColor getRed:green:blue:alpha. The method fails and returns false when the user passes a color of type UIDeviceWhiteColorSpace but works as expected for UIDeviceRGBColorSpace. This is a poor experience for users of this API.

Expected Results:
UIColor getRed:green:blue:alpha could and should create the RGB components based on a percentage of the white value. For example red = white * 1.0, green = white * 1.0, blue = white * 1.0. This would be extremely helpful and reduce code redundancy.

Actual Results:
UIColor getRed:green:blue:alpha doesn't work when the UIColor object is a UIDeviceWhiteColorSpace color.

Regression:

Notes:

Comments

It looks like no more issue at least on iOS 16

By speakus.net at July 13, 2023, 1:46 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!