Just in the process of converting my code from swift 2.3 to 3. In the old code I created a gradient through the following code:
let colours:CFArrayRef = [tColour.CGColor, bColour.CGColor]
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradientCreateWithColors(colorSpace, colours, nil)
When Xcode 8 converted the code it changed it to the following:
let colours:CFArray = [tColour.cgColor, bColour.cgColor]
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradient(colorsSpace: colorSpace, colors: colours, locations: nil)
However the code produces the following error:
Contextual type 'CFArray' cannot be used with array literal
Can anybody suggest how to convert the code properly.
With thanks
Reza
Cast the type
let colours = [tColour.cgColor, bColour.cgColor] as CFArray
let colorSpace = CGColorSpaceCreateDeviceRGB()
let gradient = CGGradient(colorsSpace: colorSpace, colors: colours , locations: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With