UIDeviceRGBColor getRed: green: blue: alpha is an unrecognized selector, not because of memory management

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

I did the following with an instance of UIColor *firstColour :

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

This worked great on a simulator. Then I tested it on my device and got this error:

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

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

I turned on Zombie, but apparently this is not a memory management issue, as most people say on the forums. And I can not find the documentation for UIDeviceRGBColor , so I do not know how it should behave. Does anyone know why this happened, and above all, if it is likely to repeat with another method?

Thanks.

+4
source share
1 answer

getRed:green:blue:alpha: launch of iOS 5.0 is available in UIColor. Most likely, the problem is that your device has an earlier version of the OS, where this method is not available.

In an older OS, you may have to extract color components from the CGColorRef base structure using the functions CGColorGetComponents / CGColorGetNumberOfComponents

+7
source

Source: https://habr.com/ru/post/1413711/


All Articles