将 Mojave Accent 颜色转换为 RGBA

Convert Mojave Accent colour to RGBA

在以 10.14 作为 macOS 部署目标的项目中尝试以下代码:

    let colour = NSColor.controlAccentColor
    var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
    colour.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
    print("RGBA = (\(red), \(green), \(blue), \(alpha))")

getRed 的调用冻结并且 print 永远无法控制。

需要转换为 RGB 颜色 space:

let colour = NSColor.controlAccentColor
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
colour.usingColorSpace(.sRGB)!.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
print("RGBA = (\(red), \(green), \(blue), \(alpha))")  // Works OK