CGFloat colorR = color.red;
It worked for a few builds, but then I modified some code that has nothing to do with color and suddenly that line crashes my app every time I try to run through it, even after undoing those changes.
NSLog(@"%@", color.CGColor);
//<CGColor %p> [<CGColorSpace %p> (kCGColorSpaceDeviceRGB)] ( 0.2 0.5 0.7 1 )
NSLog(@"%f", color.red);
//-[UIDeviceRGBColor red]: unrecognized selector sent to instance
Is the availability and (rare) correct function of color.red a bug?
-red is no public instance method for UIColor. UIColors could be represented in any color space and some conversion might be involved. To read the raw RGB components from a UIColor object you must use the method:
- (BOOL)getRed:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alphaI don’t know why color.red sometimes works – it could be that certain colors use one of the class cluster instances internally with that method and other times they are stored in another format.