Whilst the code below worked previously, it has stopped working in Xcode 8 Beta 4, presumably because the components return was a very un-Swift-y C-array of floats,
I may be mistaking something, but you can find this in the imported header of CGColor.
/* Return the color components (including alpha) associated with `color'. */
@available(OSX 10.3, *)
public var __unsafeComponents: UnsafePointer? { get }
Isn't this what you are looking for?
I can write something like this:
public var cgColour: CGColor {
get {
return CGColor(red: self.colourRed, green: self.colourGreen, blue: self.colourBlue, alpha: self.colourAlpha)
}
set {
if let comps = newValue.__unsafeComponents, newValue.numberOfComponents == 4 {
self.colourRed = comps[0]
self.colourGreen = comps[1]
self.colourBlue = comps[2]
self.colourAlpha = comps[3]
}
}
}
It works as I expect, but I'm not sure it's as you expect, or Apple would treat this as using a private API. (Apple's latest documentation of CGColor does not contain double-underscore leaded symbols.)