swift 5.3 - CGColor.init(red: r, green: g, blue: b, alpha: 1.0) returns NSObject for macOs

I am trying to create a CGColor in Swift 5.3 in macOS Catalina 10.15.7, using:
Code Block
let colour : CGColor = CGColor.init(red: r, green: g, blue: b, alpha: 1.0)

where r,g,b, are between 0.0 and 1.0, but the returned object is a NSObject. Same result as using
Code Block
let colour : CGColor = NSColor.init(red: r, green: g, blue: b, alpha: 1.0).cgColor

The NSColor is created correctly but at retrieve the CGColor, the result is NSObject.

Some suggestions.
Thanks.

Manuel

the returned object is a NSObject

How have you checked that?

With the following code:
Code Block
let colour : CGColor = CGColor.init(red: r, green: g, blue: b, alpha: 1.0)
print(colour)

I get this:
Code Block
<CGColor 0x6000026127c0> [<CGColorSpace 0x600002605320> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Generic RGB Profile)] ( 1 0.5 0.1 1 )

(Tested with Xcode 12.1 on macOS Catalina 10.15.7.)

I guess you have only check it in the variable inspector of the Debug area. CGColor is a Core Foundation type and the debugger of Xcode does not know much about it.


You may want to send a feedback to request improving the info in the Debug area.
In Xcode debug area I can reed:

<CGColor 0x600002617de0> [<CGColorSpace 0x600002614600> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0.176471 0.176471 0.176471 1 )

but in Xcode Variables area:

Code Block
color = (NSObject) 0x0000600002617de0

The desired color it not drawing.

The desired color it not drawing.

It is not mentioned in your opening post.
It is not because NSObject shown in the Debug area, but some other things may be affecting.

Please explain what is your expected result, and what is the actual result.
And please show enough code to reproduce the issue.
Also show the exact values you give to r, g, b.
And describe the color you get (on which drawing ?)
Update: Already works, was an error in the declaration of my func by personal fatigue. Sorry by that. :(
swift 5.3 - CGColor.init(red: r, green: g, blue: b, alpha: 1.0) returns NSObject for macOs
 
 
Q