[英]Fast method to cast [Float] to [CGFloat]?
I'm having a brain cramp this afternoon. 今天下午我脑部抽筋。 This should be easy.
这应该很容易。
I did read the docs. 我确实阅读了文档。
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TypeCasting.html
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TypeCasting.html
It's easy to convert single instances of Float <> CGFloat but I'm looking for a fast method to cast a LARGE array > 500,000 elements of [Float] to [CGFloat]. 转换Float <> CGFloat的单个实例很容易,但是我正在寻找一种快速方法,将大于500,000个[Float]元素的大数组转换为[CGFloat]。
var sphereRadiusFloat:[Float] = [0.0,1.0,2.0]
var sphereRadiusCGFloat:[CGFloat] = []
sphereRadiusCGFloat = sphereRadiusFloat as CGFloat
The error is 错误是
CGFloat is not convertible to [CGFloat]
CGFloat不能转换为[CGFloat]
I also tried 我也试过
sphereRadiusCGFloat = CGFloat(sphereRadiusFloat)
which gives error 这给出了错误
Could not find an overload operator for 'init' that accepts supplied arguments.
无法找到接受提供的参数的'init'重载运算符。
您可以使用map进行以下操作:
sphereRadiusCGFloat = sphereRadiusFloat.map{CGFloat($0)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.