Question

I solved my problem by using CGColorGetComponents, but I would like to understand exactly what was the reason.

I was doing the following with an instance of UIColor *firstColour :

[firstColour getRed:&r green:&g blue:&b alpha:nil];

This was working perfectly fine on simulator. Then I tested it on my device, and got this error :

UIDeviceRGBColor getRed:green:blue:alpha unrecognized selector sent to instance

After some research on the Internet I found that UIColor is actually replaced by subclasses, like UIDeviceRGBColor. Fine, but shouldn't subclasses work just like UIColor and accept (at least) the same methods ?

I enabled Zombie but apparently this wasn't a memory management issue, like most people say on forums. And I can't find documentation for UIDeviceRGBColor so I don't know how it is supposed to behave. Does someone know why it happened, and above all, if this is likely to happen again with another method ?

Thank you.

Was it helpful?

Solution

getRed:green:blue:alpha: method in UIColor is available starting iOS 5.0. Most likely the problem is that your device has older OS version where that method is not available.

On older OS you'll probably have to retrieve color components from underlying CGColorRef structure using CGColorGetComponents/CGColorGetNumberOfComponents functions

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top