在Xcode 8(Swift 3)中将Swift数组转换为CFArray [英] Converting Swift array to CFArray in Xcode 8 (Swift 3)
本文介绍了在Xcode 8(Swift 3)中将Swift数组转换为CFArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这不再适用于Xcode 8 beta 6:
This no longer works in Xcode 8 beta 6:
let colors:CFArray = [fromColor.cgColor, toColor.cgColor]
或
let gradient:CGGradient = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors:[fromColor.cgColor, toColor.cgColor], locations:[0.0, 1.0])!
错误是:上下文类型'CFArray'不能与数组文字一起使用
The error is: Contextual type 'CFArray' cannot be used with array literal
从数组转换为CFArray的最新方法是什么?
What's the latest way to convert from array to CFArray?
推荐答案
如果添加强制转换as CFArray
:
let colors = [fromColor.cgColor, toColor.cgColor] as CFArray
或者您可以在通话中添加演员表
or you can add the cast in a call:
let gradient = CGGradient(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors:[fromColor.cgColor, toColor.cgColor] as CFArray, locations:[0.0, 1.0])!
在Swift 3(Xcode 8 beta 6)中,隐式转换为桥接类型
In Swift 3 (Xcode 8 beta 6), implicit casting to bridged types has been removed. In some cases, like this one, you will need to add explicit casting to make it work.
这篇关于在Xcode 8(Swift 3)中将Swift数组转换为CFArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文