swift 3 的 CGGradient 问题

CGGradient issues with swift 3

正在将我的代码从 swift 2.3 转换为 3。在旧代码中,我通过以下代码创建了一个渐变:

        let colours:CFArrayRef = [tColour.CGColor, bColour.CGColor]
        let colorSpace = CGColorSpaceCreateDeviceRGB()
        let gradient = CGGradientCreateWithColors(colorSpace, colours, nil)

当 Xcode 8 转换代码时,它更改为以下内容:

    let colours:CFArray = [tColour.cgColor, bColour.cgColor]
    let colorSpace = CGColorSpaceCreateDeviceRGB()
    let gradient = CGGradient(colorsSpace: colorSpace, colors: colours, locations: nil)

但是代码会产生以下错误:

Contextual type 'CFArray' cannot be used with array literal

任何人都可以建议如何正确转换代码。
谢谢
礼萨

投类型

let colours = [tColour.cgColor, bColour.cgColor] as CFArray
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradient(colorsSpace: colorSpace, colors: colours , locations: nil)