Basically all I want to do is to compare a layer.fillColor
which is a CGColor
with UIColor.black.cgColor
.
The function CGColorEqualToColor
is now deprecated in Swift 4.
I have tried:
if(layer.fillColor === UIColor.black.cgColor){
return
}
And it still doesn't work. I guess they must have the same kCGColorSpaceModel.
This is the output of each color in logs
<CGColor 0x1c02a15c0> [<CGColorSpace 0x1c02a0a20> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1; extended range)] ( 0 0 0 1 )
<CGColor 0x1c008e290> [<CGColorSpace 0x1c02a0f60> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; Generic Gray Gamma 2.2 Profile; extended range)] ( 0 1 )
What's the solution?
Here's an extension for
CGColor
that checks if the given color is black or not. This works with colors in the RGB and greyscale color spaces.You can use this as: