Problem when using UIColor RGB black as a key in NSMutableDictionary

I can set UIColor objects as keys in NSMutableDictionary all day long, and all is well and happily ...

For instance:

[myDict setObject:foo forKey:[UIColor redColor]]; 

This works fine ... IF I try to use the following:

UIColor *black = [[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:1];
[myDict setObject:foo forKey:black];

It always gives me:

- [UIDeviceRGBColor copyWithZone:]: unrecognized selector sent to instance 0x691be80

The reasons why I define black in the RGB color space do not matter for this question, just know that I have to define it that way. I donโ€™t understand why this and this color alone is causing me a problem, and why is the error a copyWithZone error?

For recording, [UIColor blackColor] works like a key, but since it is not an RGB color space, it is not suitable for my application.

+3
1

, " UIColor "?

NSMutableDictionary " NSCopying". UIColor , .

, , UIColor, , , NSCopying, UIDeviceRGBColor .

UIColor -, NSCopying, -isEqualTo: .., , .

+4

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


All Articles